{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "name": "Chapter 4: Data Transformation.ipynb",
      "provenance": [],
      "collapsed_sections": []
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    }
  },
  "cells": [
    {
      "cell_type": "code",
      "metadata": {
        "id": "Ts_Ae-UdFVTX",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "import pandas as pd\n",
        "import numpy as np\n"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "3TtoVSXyzdzq",
        "colab_type": "text"
      },
      "source": [
        "# Combining dataframes\n",
        "\n"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "qGy0ch2y5MeE",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "dataFrame1 =  pd.DataFrame({ 'StudentID': [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29], 'Score' : [89, 39, 50, 97, 22, 66, 31, 51, 71, 91, 56, 32, 52, 73, 92]})\n",
        "dataFrame2 =  pd.DataFrame({'StudentID': [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30], 'Score': [98, 93, 44, 77, 69, 56, 31, 53, 78, 93, 56, 77, 33, 56, 27]})\n",
        "\n",
        "# In the dataset above, the first column contains information about student identifier and the second column contains their respective scores in any subject. The structure of the dataframes is same in the bothe case. In this case, we would need to concatenate both of them. "
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "jkgHbGof7jwO",
        "colab_type": "code",
        "outputId": "84a6cd36-c185-424a-8312-e2ca607930fe",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 979
        }
      },
      "source": [
        "# We can do that by using Pandas concat() method. \n",
        "\n",
        "dataframe = pd.concat([dataFrame1, dataFrame2], ignore_index=True)\n",
        "dataframe"
      ],
      "execution_count": 4,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>StudentID</th>\n",
              "      <th>Score</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>1</td>\n",
              "      <td>89</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>3</td>\n",
              "      <td>39</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>5</td>\n",
              "      <td>50</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3</th>\n",
              "      <td>7</td>\n",
              "      <td>97</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>4</th>\n",
              "      <td>9</td>\n",
              "      <td>22</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>5</th>\n",
              "      <td>11</td>\n",
              "      <td>66</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>6</th>\n",
              "      <td>13</td>\n",
              "      <td>31</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>7</th>\n",
              "      <td>15</td>\n",
              "      <td>51</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>8</th>\n",
              "      <td>17</td>\n",
              "      <td>71</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>9</th>\n",
              "      <td>19</td>\n",
              "      <td>91</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>10</th>\n",
              "      <td>21</td>\n",
              "      <td>56</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>11</th>\n",
              "      <td>23</td>\n",
              "      <td>32</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>12</th>\n",
              "      <td>25</td>\n",
              "      <td>52</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>13</th>\n",
              "      <td>27</td>\n",
              "      <td>73</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>14</th>\n",
              "      <td>29</td>\n",
              "      <td>92</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>15</th>\n",
              "      <td>2</td>\n",
              "      <td>98</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>16</th>\n",
              "      <td>4</td>\n",
              "      <td>93</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>17</th>\n",
              "      <td>6</td>\n",
              "      <td>44</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>18</th>\n",
              "      <td>8</td>\n",
              "      <td>77</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>19</th>\n",
              "      <td>10</td>\n",
              "      <td>69</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>20</th>\n",
              "      <td>12</td>\n",
              "      <td>56</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>21</th>\n",
              "      <td>14</td>\n",
              "      <td>31</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>22</th>\n",
              "      <td>16</td>\n",
              "      <td>53</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>23</th>\n",
              "      <td>18</td>\n",
              "      <td>78</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>24</th>\n",
              "      <td>20</td>\n",
              "      <td>93</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>25</th>\n",
              "      <td>22</td>\n",
              "      <td>56</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>26</th>\n",
              "      <td>24</td>\n",
              "      <td>77</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>27</th>\n",
              "      <td>26</td>\n",
              "      <td>33</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>28</th>\n",
              "      <td>28</td>\n",
              "      <td>56</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>29</th>\n",
              "      <td>30</td>\n",
              "      <td>27</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ],
            "text/plain": [
              "    StudentID  Score\n",
              "0           1     89\n",
              "1           3     39\n",
              "2           5     50\n",
              "3           7     97\n",
              "4           9     22\n",
              "5          11     66\n",
              "6          13     31\n",
              "7          15     51\n",
              "8          17     71\n",
              "9          19     91\n",
              "10         21     56\n",
              "11         23     32\n",
              "12         25     52\n",
              "13         27     73\n",
              "14         29     92\n",
              "15          2     98\n",
              "16          4     93\n",
              "17          6     44\n",
              "18          8     77\n",
              "19         10     69\n",
              "20         12     56\n",
              "21         14     31\n",
              "22         16     53\n",
              "23         18     78\n",
              "24         20     93\n",
              "25         22     56\n",
              "26         24     77\n",
              "27         26     33\n",
              "28         28     56\n",
              "29         30     27"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 4
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "U8KearUy9X6g",
        "colab_type": "text"
      },
      "source": [
        "The argument ignore_index creates new index and its absense keeps the original indices. Note, we combined the dataframes along axis=0, that is to say, we combined together along same direction. What if we want to combine both side by side. Then we have to specify axis = 1.  Check the output and see the difference. "
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "jaH8srvM-kNo",
        "colab_type": "code",
        "outputId": "71d847f6-eccf-4902-b34b-3ac2eb6f4a39",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 514
        }
      },
      "source": [
        "pd.concat([dataFrame1, dataFrame2], axis=1)"
      ],
      "execution_count": 5,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>StudentID</th>\n",
              "      <th>Score</th>\n",
              "      <th>StudentID</th>\n",
              "      <th>Score</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>1</td>\n",
              "      <td>89</td>\n",
              "      <td>2</td>\n",
              "      <td>98</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>3</td>\n",
              "      <td>39</td>\n",
              "      <td>4</td>\n",
              "      <td>93</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>5</td>\n",
              "      <td>50</td>\n",
              "      <td>6</td>\n",
              "      <td>44</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3</th>\n",
              "      <td>7</td>\n",
              "      <td>97</td>\n",
              "      <td>8</td>\n",
              "      <td>77</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>4</th>\n",
              "      <td>9</td>\n",
              "      <td>22</td>\n",
              "      <td>10</td>\n",
              "      <td>69</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>5</th>\n",
              "      <td>11</td>\n",
              "      <td>66</td>\n",
              "      <td>12</td>\n",
              "      <td>56</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>6</th>\n",
              "      <td>13</td>\n",
              "      <td>31</td>\n",
              "      <td>14</td>\n",
              "      <td>31</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>7</th>\n",
              "      <td>15</td>\n",
              "      <td>51</td>\n",
              "      <td>16</td>\n",
              "      <td>53</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>8</th>\n",
              "      <td>17</td>\n",
              "      <td>71</td>\n",
              "      <td>18</td>\n",
              "      <td>78</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>9</th>\n",
              "      <td>19</td>\n",
              "      <td>91</td>\n",
              "      <td>20</td>\n",
              "      <td>93</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>10</th>\n",
              "      <td>21</td>\n",
              "      <td>56</td>\n",
              "      <td>22</td>\n",
              "      <td>56</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>11</th>\n",
              "      <td>23</td>\n",
              "      <td>32</td>\n",
              "      <td>24</td>\n",
              "      <td>77</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>12</th>\n",
              "      <td>25</td>\n",
              "      <td>52</td>\n",
              "      <td>26</td>\n",
              "      <td>33</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>13</th>\n",
              "      <td>27</td>\n",
              "      <td>73</td>\n",
              "      <td>28</td>\n",
              "      <td>56</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>14</th>\n",
              "      <td>29</td>\n",
              "      <td>92</td>\n",
              "      <td>30</td>\n",
              "      <td>27</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ],
            "text/plain": [
              "    StudentID  Score  StudentID  Score\n",
              "0           1     89          2     98\n",
              "1           3     39          4     93\n",
              "2           5     50          6     44\n",
              "3           7     97          8     77\n",
              "4           9     22         10     69\n",
              "5          11     66         12     56\n",
              "6          13     31         14     31\n",
              "7          15     51         16     53\n",
              "8          17     71         18     78\n",
              "9          19     91         20     93\n",
              "10         21     56         22     56\n",
              "11         23     32         24     77\n",
              "12         25     52         26     33\n",
              "13         27     73         28     56\n",
              "14         29     92         30     27"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 5
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "MzhOAb7BCf33",
        "colab_type": "text"
      },
      "source": [
        "# Merging\n",
        "\n",
        "In the first example, you received two files for same subject. Now, consider the use case where you are teaching two courses. So, you will get two dataframes from each sections: two for Software engieering course and another two for Introduction to Machine learning course. Check the figure given below:"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "vSlCBOZ4EH-1",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "df1SE =  pd.DataFrame({ 'StudentID': [9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29], 'ScoreSE' : [22, 66, 31, 51, 71, 91, 56, 32, 52, 73, 92]})\n",
        "df2SE =  pd.DataFrame({'StudentID': [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30], 'ScoreSE': [98, 93, 44, 77, 69, 56, 31, 53, 78, 93, 56, 77, 33, 56, 27]})\n",
        "\n",
        "df1ML =  pd.DataFrame({ 'StudentID': [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29], 'ScoreML' : [39, 49, 55, 77, 52, 86, 41, 77, 73, 51, 86, 82, 92, 23, 49]})\n",
        "df2ML =  pd.DataFrame({'StudentID': [2, 4, 6, 8, 10, 12, 14, 16, 18, 20], 'ScoreML': [93, 44, 78, 97, 87, 89, 39, 43, 88, 78]})"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "aI4ttuW7EmxY",
        "colab_type": "text"
      },
      "source": [
        "As you can see in the dataset above, you have two dataframes for each subjects. So the first task would be to concatenate these two subjects into one. Secondly, these students have taken Introduction to Machine Learning course as well. So, we need to merge these score into the same dataframes. There are several ways to do this. Let us explore some options. "
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "wNLb0IxdFzde",
        "colab_type": "code",
        "outputId": "7ef106a3-fcfa-414b-e67f-580a1cf98917",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 855
        }
      },
      "source": [
        "# Option 1\n",
        "dfSE = pd.concat([df1SE, df2SE], ignore_index=True)\n",
        "dfML = pd.concat([df1ML, df2ML], ignore_index=True)\n",
        "\n",
        "df = pd.concat([dfML, dfSE], axis=1)\n",
        "df"
      ],
      "execution_count": 7,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>StudentID</th>\n",
              "      <th>ScoreML</th>\n",
              "      <th>StudentID</th>\n",
              "      <th>ScoreSE</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>1.0</td>\n",
              "      <td>39.0</td>\n",
              "      <td>9</td>\n",
              "      <td>22</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>3.0</td>\n",
              "      <td>49.0</td>\n",
              "      <td>11</td>\n",
              "      <td>66</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>5.0</td>\n",
              "      <td>55.0</td>\n",
              "      <td>13</td>\n",
              "      <td>31</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3</th>\n",
              "      <td>7.0</td>\n",
              "      <td>77.0</td>\n",
              "      <td>15</td>\n",
              "      <td>51</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>4</th>\n",
              "      <td>9.0</td>\n",
              "      <td>52.0</td>\n",
              "      <td>17</td>\n",
              "      <td>71</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>5</th>\n",
              "      <td>11.0</td>\n",
              "      <td>86.0</td>\n",
              "      <td>19</td>\n",
              "      <td>91</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>6</th>\n",
              "      <td>13.0</td>\n",
              "      <td>41.0</td>\n",
              "      <td>21</td>\n",
              "      <td>56</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>7</th>\n",
              "      <td>15.0</td>\n",
              "      <td>77.0</td>\n",
              "      <td>23</td>\n",
              "      <td>32</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>8</th>\n",
              "      <td>17.0</td>\n",
              "      <td>73.0</td>\n",
              "      <td>25</td>\n",
              "      <td>52</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>9</th>\n",
              "      <td>19.0</td>\n",
              "      <td>51.0</td>\n",
              "      <td>27</td>\n",
              "      <td>73</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>10</th>\n",
              "      <td>21.0</td>\n",
              "      <td>86.0</td>\n",
              "      <td>29</td>\n",
              "      <td>92</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>11</th>\n",
              "      <td>23.0</td>\n",
              "      <td>82.0</td>\n",
              "      <td>2</td>\n",
              "      <td>98</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>12</th>\n",
              "      <td>25.0</td>\n",
              "      <td>92.0</td>\n",
              "      <td>4</td>\n",
              "      <td>93</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>13</th>\n",
              "      <td>27.0</td>\n",
              "      <td>23.0</td>\n",
              "      <td>6</td>\n",
              "      <td>44</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>14</th>\n",
              "      <td>29.0</td>\n",
              "      <td>49.0</td>\n",
              "      <td>8</td>\n",
              "      <td>77</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>15</th>\n",
              "      <td>2.0</td>\n",
              "      <td>93.0</td>\n",
              "      <td>10</td>\n",
              "      <td>69</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>16</th>\n",
              "      <td>4.0</td>\n",
              "      <td>44.0</td>\n",
              "      <td>12</td>\n",
              "      <td>56</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>17</th>\n",
              "      <td>6.0</td>\n",
              "      <td>78.0</td>\n",
              "      <td>14</td>\n",
              "      <td>31</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>18</th>\n",
              "      <td>8.0</td>\n",
              "      <td>97.0</td>\n",
              "      <td>16</td>\n",
              "      <td>53</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>19</th>\n",
              "      <td>10.0</td>\n",
              "      <td>87.0</td>\n",
              "      <td>18</td>\n",
              "      <td>78</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>20</th>\n",
              "      <td>12.0</td>\n",
              "      <td>89.0</td>\n",
              "      <td>20</td>\n",
              "      <td>93</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>21</th>\n",
              "      <td>14.0</td>\n",
              "      <td>39.0</td>\n",
              "      <td>22</td>\n",
              "      <td>56</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>22</th>\n",
              "      <td>16.0</td>\n",
              "      <td>43.0</td>\n",
              "      <td>24</td>\n",
              "      <td>77</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>23</th>\n",
              "      <td>18.0</td>\n",
              "      <td>88.0</td>\n",
              "      <td>26</td>\n",
              "      <td>33</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>24</th>\n",
              "      <td>20.0</td>\n",
              "      <td>78.0</td>\n",
              "      <td>28</td>\n",
              "      <td>56</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>25</th>\n",
              "      <td>NaN</td>\n",
              "      <td>NaN</td>\n",
              "      <td>30</td>\n",
              "      <td>27</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ],
            "text/plain": [
              "    StudentID  ScoreML  StudentID  ScoreSE\n",
              "0         1.0     39.0          9       22\n",
              "1         3.0     49.0         11       66\n",
              "2         5.0     55.0         13       31\n",
              "3         7.0     77.0         15       51\n",
              "4         9.0     52.0         17       71\n",
              "5        11.0     86.0         19       91\n",
              "6        13.0     41.0         21       56\n",
              "7        15.0     77.0         23       32\n",
              "8        17.0     73.0         25       52\n",
              "9        19.0     51.0         27       73\n",
              "10       21.0     86.0         29       92\n",
              "11       23.0     82.0          2       98\n",
              "12       25.0     92.0          4       93\n",
              "13       27.0     23.0          6       44\n",
              "14       29.0     49.0          8       77\n",
              "15        2.0     93.0         10       69\n",
              "16        4.0     44.0         12       56\n",
              "17        6.0     78.0         14       31\n",
              "18        8.0     97.0         16       53\n",
              "19       10.0     87.0         18       78\n",
              "20       12.0     89.0         20       93\n",
              "21       14.0     39.0         22       56\n",
              "22       16.0     43.0         24       77\n",
              "23       18.0     88.0         26       33\n",
              "24       20.0     78.0         28       56\n",
              "25        NaN      NaN         30       27"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 7
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "czCSen-bGY3R",
        "colab_type": "code",
        "outputId": "4ba02463-5beb-4311-bd07-f661f6a4fd15",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 700
        }
      },
      "source": [
        "# Option 2\n",
        "dfSE = pd.concat([df1SE, df2SE], ignore_index=True)\n",
        "dfML = pd.concat([df1ML, df2ML], ignore_index=True)\n",
        "\n",
        "df = dfSE.merge(dfML, how='inner')\n",
        "df\n",
        "\n",
        "# Here, you will perform inner join with each dataframe. That is to say, if an item exists on the both dataframe, will be included in the new dataframe. This means, we will get the list of students who are appearing in both the courses. "
      ],
      "execution_count": 8,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>StudentID</th>\n",
              "      <th>ScoreSE</th>\n",
              "      <th>ScoreML</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>9</td>\n",
              "      <td>22</td>\n",
              "      <td>52</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>11</td>\n",
              "      <td>66</td>\n",
              "      <td>86</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>13</td>\n",
              "      <td>31</td>\n",
              "      <td>41</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3</th>\n",
              "      <td>15</td>\n",
              "      <td>51</td>\n",
              "      <td>77</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>4</th>\n",
              "      <td>17</td>\n",
              "      <td>71</td>\n",
              "      <td>73</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>5</th>\n",
              "      <td>19</td>\n",
              "      <td>91</td>\n",
              "      <td>51</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>6</th>\n",
              "      <td>21</td>\n",
              "      <td>56</td>\n",
              "      <td>86</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>7</th>\n",
              "      <td>23</td>\n",
              "      <td>32</td>\n",
              "      <td>82</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>8</th>\n",
              "      <td>25</td>\n",
              "      <td>52</td>\n",
              "      <td>92</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>9</th>\n",
              "      <td>27</td>\n",
              "      <td>73</td>\n",
              "      <td>23</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>10</th>\n",
              "      <td>29</td>\n",
              "      <td>92</td>\n",
              "      <td>49</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>11</th>\n",
              "      <td>2</td>\n",
              "      <td>98</td>\n",
              "      <td>93</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>12</th>\n",
              "      <td>4</td>\n",
              "      <td>93</td>\n",
              "      <td>44</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>13</th>\n",
              "      <td>6</td>\n",
              "      <td>44</td>\n",
              "      <td>78</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>14</th>\n",
              "      <td>8</td>\n",
              "      <td>77</td>\n",
              "      <td>97</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>15</th>\n",
              "      <td>10</td>\n",
              "      <td>69</td>\n",
              "      <td>87</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>16</th>\n",
              "      <td>12</td>\n",
              "      <td>56</td>\n",
              "      <td>89</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>17</th>\n",
              "      <td>14</td>\n",
              "      <td>31</td>\n",
              "      <td>39</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>18</th>\n",
              "      <td>16</td>\n",
              "      <td>53</td>\n",
              "      <td>43</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>19</th>\n",
              "      <td>18</td>\n",
              "      <td>78</td>\n",
              "      <td>88</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>20</th>\n",
              "      <td>20</td>\n",
              "      <td>93</td>\n",
              "      <td>78</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ],
            "text/plain": [
              "    StudentID  ScoreSE  ScoreML\n",
              "0           9       22       52\n",
              "1          11       66       86\n",
              "2          13       31       41\n",
              "3          15       51       77\n",
              "4          17       71       73\n",
              "5          19       91       51\n",
              "6          21       56       86\n",
              "7          23       32       82\n",
              "8          25       52       92\n",
              "9          27       73       23\n",
              "10         29       92       49\n",
              "11          2       98       93\n",
              "12          4       93       44\n",
              "13          6       44       78\n",
              "14          8       77       97\n",
              "15         10       69       87\n",
              "16         12       56       89\n",
              "17         14       31       39\n",
              "18         16       53       43\n",
              "19         18       78       88\n",
              "20         20       93       78"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 8
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "lHcrG5LwHQTf",
        "colab_type": "code",
        "outputId": "49234e55-105c-4117-c704-8c1498a72065",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 855
        }
      },
      "source": [
        "# Option 3\n",
        "dfSE = pd.concat([df1SE, df2SE], ignore_index=True)\n",
        "dfML = pd.concat([df1ML, df2ML], ignore_index=True)\n",
        "\n",
        "df = dfSE.merge(dfML, how='left')\n",
        "df"
      ],
      "execution_count": 9,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>StudentID</th>\n",
              "      <th>ScoreSE</th>\n",
              "      <th>ScoreML</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>9</td>\n",
              "      <td>22</td>\n",
              "      <td>52.0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>11</td>\n",
              "      <td>66</td>\n",
              "      <td>86.0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>13</td>\n",
              "      <td>31</td>\n",
              "      <td>41.0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3</th>\n",
              "      <td>15</td>\n",
              "      <td>51</td>\n",
              "      <td>77.0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>4</th>\n",
              "      <td>17</td>\n",
              "      <td>71</td>\n",
              "      <td>73.0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>5</th>\n",
              "      <td>19</td>\n",
              "      <td>91</td>\n",
              "      <td>51.0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>6</th>\n",
              "      <td>21</td>\n",
              "      <td>56</td>\n",
              "      <td>86.0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>7</th>\n",
              "      <td>23</td>\n",
              "      <td>32</td>\n",
              "      <td>82.0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>8</th>\n",
              "      <td>25</td>\n",
              "      <td>52</td>\n",
              "      <td>92.0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>9</th>\n",
              "      <td>27</td>\n",
              "      <td>73</td>\n",
              "      <td>23.0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>10</th>\n",
              "      <td>29</td>\n",
              "      <td>92</td>\n",
              "      <td>49.0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>11</th>\n",
              "      <td>2</td>\n",
              "      <td>98</td>\n",
              "      <td>93.0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>12</th>\n",
              "      <td>4</td>\n",
              "      <td>93</td>\n",
              "      <td>44.0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>13</th>\n",
              "      <td>6</td>\n",
              "      <td>44</td>\n",
              "      <td>78.0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>14</th>\n",
              "      <td>8</td>\n",
              "      <td>77</td>\n",
              "      <td>97.0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>15</th>\n",
              "      <td>10</td>\n",
              "      <td>69</td>\n",
              "      <td>87.0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>16</th>\n",
              "      <td>12</td>\n",
              "      <td>56</td>\n",
              "      <td>89.0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>17</th>\n",
              "      <td>14</td>\n",
              "      <td>31</td>\n",
              "      <td>39.0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>18</th>\n",
              "      <td>16</td>\n",
              "      <td>53</td>\n",
              "      <td>43.0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>19</th>\n",
              "      <td>18</td>\n",
              "      <td>78</td>\n",
              "      <td>88.0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>20</th>\n",
              "      <td>20</td>\n",
              "      <td>93</td>\n",
              "      <td>78.0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>21</th>\n",
              "      <td>22</td>\n",
              "      <td>56</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>22</th>\n",
              "      <td>24</td>\n",
              "      <td>77</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>23</th>\n",
              "      <td>26</td>\n",
              "      <td>33</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>24</th>\n",
              "      <td>28</td>\n",
              "      <td>56</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>25</th>\n",
              "      <td>30</td>\n",
              "      <td>27</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ],
            "text/plain": [
              "    StudentID  ScoreSE  ScoreML\n",
              "0           9       22     52.0\n",
              "1          11       66     86.0\n",
              "2          13       31     41.0\n",
              "3          15       51     77.0\n",
              "4          17       71     73.0\n",
              "5          19       91     51.0\n",
              "6          21       56     86.0\n",
              "7          23       32     82.0\n",
              "8          25       52     92.0\n",
              "9          27       73     23.0\n",
              "10         29       92     49.0\n",
              "11          2       98     93.0\n",
              "12          4       93     44.0\n",
              "13          6       44     78.0\n",
              "14          8       77     97.0\n",
              "15         10       69     87.0\n",
              "16         12       56     89.0\n",
              "17         14       31     39.0\n",
              "18         16       53     43.0\n",
              "19         18       78     88.0\n",
              "20         20       93     78.0\n",
              "21         22       56      NaN\n",
              "22         24       77      NaN\n",
              "23         26       33      NaN\n",
              "24         28       56      NaN\n",
              "25         30       27      NaN"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 9
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "mD3vkd-3JNTF",
        "colab_type": "code",
        "outputId": "955218c2-efaf-4e37-ee30-6618f4a3bddc",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 824
        }
      },
      "source": [
        "# Option 4\n",
        "dfSE = pd.concat([df1SE, df2SE], ignore_index=True)\n",
        "dfML = pd.concat([df1ML, df2ML], ignore_index=True)\n",
        "\n",
        "df = dfSE.merge(dfML, how='right')\n",
        "df"
      ],
      "execution_count": 10,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>StudentID</th>\n",
              "      <th>ScoreSE</th>\n",
              "      <th>ScoreML</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>9</td>\n",
              "      <td>22.0</td>\n",
              "      <td>52</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>11</td>\n",
              "      <td>66.0</td>\n",
              "      <td>86</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>13</td>\n",
              "      <td>31.0</td>\n",
              "      <td>41</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3</th>\n",
              "      <td>15</td>\n",
              "      <td>51.0</td>\n",
              "      <td>77</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>4</th>\n",
              "      <td>17</td>\n",
              "      <td>71.0</td>\n",
              "      <td>73</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>5</th>\n",
              "      <td>19</td>\n",
              "      <td>91.0</td>\n",
              "      <td>51</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>6</th>\n",
              "      <td>21</td>\n",
              "      <td>56.0</td>\n",
              "      <td>86</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>7</th>\n",
              "      <td>23</td>\n",
              "      <td>32.0</td>\n",
              "      <td>82</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>8</th>\n",
              "      <td>25</td>\n",
              "      <td>52.0</td>\n",
              "      <td>92</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>9</th>\n",
              "      <td>27</td>\n",
              "      <td>73.0</td>\n",
              "      <td>23</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>10</th>\n",
              "      <td>29</td>\n",
              "      <td>92.0</td>\n",
              "      <td>49</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>11</th>\n",
              "      <td>2</td>\n",
              "      <td>98.0</td>\n",
              "      <td>93</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>12</th>\n",
              "      <td>4</td>\n",
              "      <td>93.0</td>\n",
              "      <td>44</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>13</th>\n",
              "      <td>6</td>\n",
              "      <td>44.0</td>\n",
              "      <td>78</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>14</th>\n",
              "      <td>8</td>\n",
              "      <td>77.0</td>\n",
              "      <td>97</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>15</th>\n",
              "      <td>10</td>\n",
              "      <td>69.0</td>\n",
              "      <td>87</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>16</th>\n",
              "      <td>12</td>\n",
              "      <td>56.0</td>\n",
              "      <td>89</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>17</th>\n",
              "      <td>14</td>\n",
              "      <td>31.0</td>\n",
              "      <td>39</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>18</th>\n",
              "      <td>16</td>\n",
              "      <td>53.0</td>\n",
              "      <td>43</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>19</th>\n",
              "      <td>18</td>\n",
              "      <td>78.0</td>\n",
              "      <td>88</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>20</th>\n",
              "      <td>20</td>\n",
              "      <td>93.0</td>\n",
              "      <td>78</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>21</th>\n",
              "      <td>1</td>\n",
              "      <td>NaN</td>\n",
              "      <td>39</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>22</th>\n",
              "      <td>3</td>\n",
              "      <td>NaN</td>\n",
              "      <td>49</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>23</th>\n",
              "      <td>5</td>\n",
              "      <td>NaN</td>\n",
              "      <td>55</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>24</th>\n",
              "      <td>7</td>\n",
              "      <td>NaN</td>\n",
              "      <td>77</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ],
            "text/plain": [
              "    StudentID  ScoreSE  ScoreML\n",
              "0           9     22.0       52\n",
              "1          11     66.0       86\n",
              "2          13     31.0       41\n",
              "3          15     51.0       77\n",
              "4          17     71.0       73\n",
              "5          19     91.0       51\n",
              "6          21     56.0       86\n",
              "7          23     32.0       82\n",
              "8          25     52.0       92\n",
              "9          27     73.0       23\n",
              "10         29     92.0       49\n",
              "11          2     98.0       93\n",
              "12          4     93.0       44\n",
              "13          6     44.0       78\n",
              "14          8     77.0       97\n",
              "15         10     69.0       87\n",
              "16         12     56.0       89\n",
              "17         14     31.0       39\n",
              "18         16     53.0       43\n",
              "19         18     78.0       88\n",
              "20         20     93.0       78\n",
              "21          1      NaN       39\n",
              "22          3      NaN       49\n",
              "23          5      NaN       55\n",
              "24          7      NaN       77"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 10
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "XubRsJqMJVIZ",
        "colab_type": "code",
        "outputId": "0acd9ce3-9e5f-4459-a601-431d8a15196d",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 979
        }
      },
      "source": [
        "# Option 5\n",
        "dfSE = pd.concat([df1SE, df2SE], ignore_index=True)\n",
        "dfML = pd.concat([df1ML, df2ML], ignore_index=True)\n",
        "\n",
        "df = dfSE.merge(dfML, how='outer')\n",
        "df"
      ],
      "execution_count": 11,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>StudentID</th>\n",
              "      <th>ScoreSE</th>\n",
              "      <th>ScoreML</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>9</td>\n",
              "      <td>22.0</td>\n",
              "      <td>52.0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>11</td>\n",
              "      <td>66.0</td>\n",
              "      <td>86.0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>13</td>\n",
              "      <td>31.0</td>\n",
              "      <td>41.0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3</th>\n",
              "      <td>15</td>\n",
              "      <td>51.0</td>\n",
              "      <td>77.0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>4</th>\n",
              "      <td>17</td>\n",
              "      <td>71.0</td>\n",
              "      <td>73.0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>5</th>\n",
              "      <td>19</td>\n",
              "      <td>91.0</td>\n",
              "      <td>51.0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>6</th>\n",
              "      <td>21</td>\n",
              "      <td>56.0</td>\n",
              "      <td>86.0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>7</th>\n",
              "      <td>23</td>\n",
              "      <td>32.0</td>\n",
              "      <td>82.0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>8</th>\n",
              "      <td>25</td>\n",
              "      <td>52.0</td>\n",
              "      <td>92.0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>9</th>\n",
              "      <td>27</td>\n",
              "      <td>73.0</td>\n",
              "      <td>23.0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>10</th>\n",
              "      <td>29</td>\n",
              "      <td>92.0</td>\n",
              "      <td>49.0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>11</th>\n",
              "      <td>2</td>\n",
              "      <td>98.0</td>\n",
              "      <td>93.0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>12</th>\n",
              "      <td>4</td>\n",
              "      <td>93.0</td>\n",
              "      <td>44.0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>13</th>\n",
              "      <td>6</td>\n",
              "      <td>44.0</td>\n",
              "      <td>78.0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>14</th>\n",
              "      <td>8</td>\n",
              "      <td>77.0</td>\n",
              "      <td>97.0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>15</th>\n",
              "      <td>10</td>\n",
              "      <td>69.0</td>\n",
              "      <td>87.0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>16</th>\n",
              "      <td>12</td>\n",
              "      <td>56.0</td>\n",
              "      <td>89.0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>17</th>\n",
              "      <td>14</td>\n",
              "      <td>31.0</td>\n",
              "      <td>39.0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>18</th>\n",
              "      <td>16</td>\n",
              "      <td>53.0</td>\n",
              "      <td>43.0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>19</th>\n",
              "      <td>18</td>\n",
              "      <td>78.0</td>\n",
              "      <td>88.0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>20</th>\n",
              "      <td>20</td>\n",
              "      <td>93.0</td>\n",
              "      <td>78.0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>21</th>\n",
              "      <td>22</td>\n",
              "      <td>56.0</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>22</th>\n",
              "      <td>24</td>\n",
              "      <td>77.0</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>23</th>\n",
              "      <td>26</td>\n",
              "      <td>33.0</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>24</th>\n",
              "      <td>28</td>\n",
              "      <td>56.0</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>25</th>\n",
              "      <td>30</td>\n",
              "      <td>27.0</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>26</th>\n",
              "      <td>1</td>\n",
              "      <td>NaN</td>\n",
              "      <td>39.0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>27</th>\n",
              "      <td>3</td>\n",
              "      <td>NaN</td>\n",
              "      <td>49.0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>28</th>\n",
              "      <td>5</td>\n",
              "      <td>NaN</td>\n",
              "      <td>55.0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>29</th>\n",
              "      <td>7</td>\n",
              "      <td>NaN</td>\n",
              "      <td>77.0</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ],
            "text/plain": [
              "    StudentID  ScoreSE  ScoreML\n",
              "0           9     22.0     52.0\n",
              "1          11     66.0     86.0\n",
              "2          13     31.0     41.0\n",
              "3          15     51.0     77.0\n",
              "4          17     71.0     73.0\n",
              "5          19     91.0     51.0\n",
              "6          21     56.0     86.0\n",
              "7          23     32.0     82.0\n",
              "8          25     52.0     92.0\n",
              "9          27     73.0     23.0\n",
              "10         29     92.0     49.0\n",
              "11          2     98.0     93.0\n",
              "12          4     93.0     44.0\n",
              "13          6     44.0     78.0\n",
              "14          8     77.0     97.0\n",
              "15         10     69.0     87.0\n",
              "16         12     56.0     89.0\n",
              "17         14     31.0     39.0\n",
              "18         16     53.0     43.0\n",
              "19         18     78.0     88.0\n",
              "20         20     93.0     78.0\n",
              "21         22     56.0      NaN\n",
              "22         24     77.0      NaN\n",
              "23         26     33.0      NaN\n",
              "24         28     56.0      NaN\n",
              "25         30     27.0      NaN\n",
              "26          1      NaN     39.0\n",
              "27          3      NaN     49.0\n",
              "28          5      NaN     55.0\n",
              "29          7      NaN     77.0"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 11
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "QOZQFDfQPQSH",
        "colab_type": "code",
        "outputId": "a07f78b6-c01d-403f-bcc1-5586410a074c",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 359
        }
      },
      "source": [
        "df = pd.read_csv('https://raw.githubusercontent.com/PacktPublishing/hands-on-exploratory-data-analysis-with-python/master/Chapter%204/sales.csv')\n",
        "df.head(10)"
      ],
      "execution_count": 12,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>Account</th>\n",
              "      <th>Company</th>\n",
              "      <th>Order</th>\n",
              "      <th>SKU</th>\n",
              "      <th>Country</th>\n",
              "      <th>Year</th>\n",
              "      <th>Quantity</th>\n",
              "      <th>UnitPrice</th>\n",
              "      <th>transactionComplete</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>123456779</td>\n",
              "      <td>Kulas Inc</td>\n",
              "      <td>99985</td>\n",
              "      <td>s9-supercomputer</td>\n",
              "      <td>Aruba</td>\n",
              "      <td>1981</td>\n",
              "      <td>5148</td>\n",
              "      <td>545</td>\n",
              "      <td>False</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>123456784</td>\n",
              "      <td>GitHub</td>\n",
              "      <td>99986</td>\n",
              "      <td>s4-supercomputer</td>\n",
              "      <td>Brazil</td>\n",
              "      <td>2001</td>\n",
              "      <td>3262</td>\n",
              "      <td>383</td>\n",
              "      <td>False</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>123456782</td>\n",
              "      <td>Kulas Inc</td>\n",
              "      <td>99990</td>\n",
              "      <td>s10-supercomputer</td>\n",
              "      <td>Montserrat</td>\n",
              "      <td>1973</td>\n",
              "      <td>9119</td>\n",
              "      <td>407</td>\n",
              "      <td>True</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3</th>\n",
              "      <td>123456783</td>\n",
              "      <td>My SQ Man</td>\n",
              "      <td>99999</td>\n",
              "      <td>s1-supercomputer</td>\n",
              "      <td>El Salvador</td>\n",
              "      <td>2015</td>\n",
              "      <td>3097</td>\n",
              "      <td>615</td>\n",
              "      <td>False</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>4</th>\n",
              "      <td>123456787</td>\n",
              "      <td>ABC Dogma</td>\n",
              "      <td>99996</td>\n",
              "      <td>s6-supercomputer</td>\n",
              "      <td>Poland</td>\n",
              "      <td>1970</td>\n",
              "      <td>3356</td>\n",
              "      <td>91</td>\n",
              "      <td>True</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>5</th>\n",
              "      <td>123456778</td>\n",
              "      <td>Super Sexy Dingo</td>\n",
              "      <td>99996</td>\n",
              "      <td>s9-supercomputer</td>\n",
              "      <td>Costa Rica</td>\n",
              "      <td>2004</td>\n",
              "      <td>2474</td>\n",
              "      <td>136</td>\n",
              "      <td>True</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>6</th>\n",
              "      <td>123456783</td>\n",
              "      <td>ABC Dogma</td>\n",
              "      <td>99981</td>\n",
              "      <td>s11-supercomputer</td>\n",
              "      <td>Spain</td>\n",
              "      <td>2006</td>\n",
              "      <td>4081</td>\n",
              "      <td>195</td>\n",
              "      <td>False</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>7</th>\n",
              "      <td>123456785</td>\n",
              "      <td>ABC Dogma</td>\n",
              "      <td>99998</td>\n",
              "      <td>s9-supercomputer</td>\n",
              "      <td>Belarus</td>\n",
              "      <td>2015</td>\n",
              "      <td>6576</td>\n",
              "      <td>603</td>\n",
              "      <td>False</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>8</th>\n",
              "      <td>123456778</td>\n",
              "      <td>Loolo INC</td>\n",
              "      <td>99997</td>\n",
              "      <td>s8-supercomputer</td>\n",
              "      <td>Mauritius</td>\n",
              "      <td>1999</td>\n",
              "      <td>2460</td>\n",
              "      <td>36</td>\n",
              "      <td>False</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>9</th>\n",
              "      <td>123456775</td>\n",
              "      <td>Kulas Inc</td>\n",
              "      <td>99997</td>\n",
              "      <td>s7-supercomputer</td>\n",
              "      <td>French Guiana</td>\n",
              "      <td>2004</td>\n",
              "      <td>1831</td>\n",
              "      <td>664</td>\n",
              "      <td>True</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ],
            "text/plain": [
              "     Account           Company  Order  ... Quantity UnitPrice  transactionComplete\n",
              "0  123456779         Kulas Inc  99985  ...     5148       545                False\n",
              "1  123456784            GitHub  99986  ...     3262       383                False\n",
              "2  123456782         Kulas Inc  99990  ...     9119       407                 True\n",
              "3  123456783         My SQ Man  99999  ...     3097       615                False\n",
              "4  123456787         ABC Dogma  99996  ...     3356        91                 True\n",
              "5  123456778  Super Sexy Dingo  99996  ...     2474       136                 True\n",
              "6  123456783         ABC Dogma  99981  ...     4081       195                False\n",
              "7  123456785         ABC Dogma  99998  ...     6576       603                False\n",
              "8  123456778         Loolo INC  99997  ...     2460        36                False\n",
              "9  123456775         Kulas Inc  99997  ...     1831       664                 True\n",
              "\n",
              "[10 rows x 9 columns]"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 12
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "3Z4LekePPX_t",
        "colab_type": "code",
        "outputId": "77654617-9022-4c46-e4fc-be556e1c3e3a",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 359
        }
      },
      "source": [
        "#@title Default title text\n",
        "#Add new colum that is the total price based on the quantity and the unit price\n",
        "\n",
        "df['TotalPrice'] = df['UnitPrice'] * df['Quantity']\n",
        "df.head(10)"
      ],
      "execution_count": 13,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>Account</th>\n",
              "      <th>Company</th>\n",
              "      <th>Order</th>\n",
              "      <th>SKU</th>\n",
              "      <th>Country</th>\n",
              "      <th>Year</th>\n",
              "      <th>Quantity</th>\n",
              "      <th>UnitPrice</th>\n",
              "      <th>transactionComplete</th>\n",
              "      <th>TotalPrice</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>123456779</td>\n",
              "      <td>Kulas Inc</td>\n",
              "      <td>99985</td>\n",
              "      <td>s9-supercomputer</td>\n",
              "      <td>Aruba</td>\n",
              "      <td>1981</td>\n",
              "      <td>5148</td>\n",
              "      <td>545</td>\n",
              "      <td>False</td>\n",
              "      <td>2805660</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>123456784</td>\n",
              "      <td>GitHub</td>\n",
              "      <td>99986</td>\n",
              "      <td>s4-supercomputer</td>\n",
              "      <td>Brazil</td>\n",
              "      <td>2001</td>\n",
              "      <td>3262</td>\n",
              "      <td>383</td>\n",
              "      <td>False</td>\n",
              "      <td>1249346</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>123456782</td>\n",
              "      <td>Kulas Inc</td>\n",
              "      <td>99990</td>\n",
              "      <td>s10-supercomputer</td>\n",
              "      <td>Montserrat</td>\n",
              "      <td>1973</td>\n",
              "      <td>9119</td>\n",
              "      <td>407</td>\n",
              "      <td>True</td>\n",
              "      <td>3711433</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3</th>\n",
              "      <td>123456783</td>\n",
              "      <td>My SQ Man</td>\n",
              "      <td>99999</td>\n",
              "      <td>s1-supercomputer</td>\n",
              "      <td>El Salvador</td>\n",
              "      <td>2015</td>\n",
              "      <td>3097</td>\n",
              "      <td>615</td>\n",
              "      <td>False</td>\n",
              "      <td>1904655</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>4</th>\n",
              "      <td>123456787</td>\n",
              "      <td>ABC Dogma</td>\n",
              "      <td>99996</td>\n",
              "      <td>s6-supercomputer</td>\n",
              "      <td>Poland</td>\n",
              "      <td>1970</td>\n",
              "      <td>3356</td>\n",
              "      <td>91</td>\n",
              "      <td>True</td>\n",
              "      <td>305396</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>5</th>\n",
              "      <td>123456778</td>\n",
              "      <td>Super Sexy Dingo</td>\n",
              "      <td>99996</td>\n",
              "      <td>s9-supercomputer</td>\n",
              "      <td>Costa Rica</td>\n",
              "      <td>2004</td>\n",
              "      <td>2474</td>\n",
              "      <td>136</td>\n",
              "      <td>True</td>\n",
              "      <td>336464</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>6</th>\n",
              "      <td>123456783</td>\n",
              "      <td>ABC Dogma</td>\n",
              "      <td>99981</td>\n",
              "      <td>s11-supercomputer</td>\n",
              "      <td>Spain</td>\n",
              "      <td>2006</td>\n",
              "      <td>4081</td>\n",
              "      <td>195</td>\n",
              "      <td>False</td>\n",
              "      <td>795795</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>7</th>\n",
              "      <td>123456785</td>\n",
              "      <td>ABC Dogma</td>\n",
              "      <td>99998</td>\n",
              "      <td>s9-supercomputer</td>\n",
              "      <td>Belarus</td>\n",
              "      <td>2015</td>\n",
              "      <td>6576</td>\n",
              "      <td>603</td>\n",
              "      <td>False</td>\n",
              "      <td>3965328</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>8</th>\n",
              "      <td>123456778</td>\n",
              "      <td>Loolo INC</td>\n",
              "      <td>99997</td>\n",
              "      <td>s8-supercomputer</td>\n",
              "      <td>Mauritius</td>\n",
              "      <td>1999</td>\n",
              "      <td>2460</td>\n",
              "      <td>36</td>\n",
              "      <td>False</td>\n",
              "      <td>88560</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>9</th>\n",
              "      <td>123456775</td>\n",
              "      <td>Kulas Inc</td>\n",
              "      <td>99997</td>\n",
              "      <td>s7-supercomputer</td>\n",
              "      <td>French Guiana</td>\n",
              "      <td>2004</td>\n",
              "      <td>1831</td>\n",
              "      <td>664</td>\n",
              "      <td>True</td>\n",
              "      <td>1215784</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ],
            "text/plain": [
              "     Account           Company  ...  transactionComplete TotalPrice\n",
              "0  123456779         Kulas Inc  ...                False    2805660\n",
              "1  123456784            GitHub  ...                False    1249346\n",
              "2  123456782         Kulas Inc  ...                 True    3711433\n",
              "3  123456783         My SQ Man  ...                False    1904655\n",
              "4  123456787         ABC Dogma  ...                 True     305396\n",
              "5  123456778  Super Sexy Dingo  ...                 True     336464\n",
              "6  123456783         ABC Dogma  ...                False     795795\n",
              "7  123456785         ABC Dogma  ...                False    3965328\n",
              "8  123456778         Loolo INC  ...                False      88560\n",
              "9  123456775         Kulas Inc  ...                 True    1215784\n",
              "\n",
              "[10 rows x 10 columns]"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 13
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "e0EtWNvlca71",
        "colab_type": "code",
        "outputId": "623dc411-2948-4f85-f168-ebf2a6ac1678",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 238
        }
      },
      "source": [
        "df['Company'].value_counts()"
      ],
      "execution_count": 14,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "My SQ Man                   869\n",
              "Kirlosker Service Center    863\n",
              "Will LLC                    862\n",
              "ABC Dogma                   848\n",
              "Kulas Inc                   840\n",
              "Gen Power                   836\n",
              "Name IT                     836\n",
              "Super Sexy Dingo            828\n",
              "GitHub                      823\n",
              "Loolo INC                   822\n",
              "SAS Web Tec                 798\n",
              "Pryianka Ji                 775\n",
              "Name: Company, dtype: int64"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 14
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "xfCdYctmc6o9",
        "colab_type": "code",
        "outputId": "0dc6124c-9dec-47ea-bf72-b811fdf6d054",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 297
        }
      },
      "source": [
        "df.describe()"
      ],
      "execution_count": 15,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>Account</th>\n",
              "      <th>Order</th>\n",
              "      <th>Year</th>\n",
              "      <th>Quantity</th>\n",
              "      <th>UnitPrice</th>\n",
              "      <th>TotalPrice</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>count</th>\n",
              "      <td>1.000000e+04</td>\n",
              "      <td>10000.000000</td>\n",
              "      <td>10000.000000</td>\n",
              "      <td>10000.000000</td>\n",
              "      <td>10000.000000</td>\n",
              "      <td>1.000000e+04</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>mean</th>\n",
              "      <td>1.234568e+08</td>\n",
              "      <td>99989.562900</td>\n",
              "      <td>1994.619800</td>\n",
              "      <td>4985.447300</td>\n",
              "      <td>355.866600</td>\n",
              "      <td>1.773301e+06</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>std</th>\n",
              "      <td>5.741156e+00</td>\n",
              "      <td>5.905551</td>\n",
              "      <td>14.432771</td>\n",
              "      <td>2868.949686</td>\n",
              "      <td>201.378478</td>\n",
              "      <td>1.540646e+06</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>min</th>\n",
              "      <td>1.234568e+08</td>\n",
              "      <td>99980.000000</td>\n",
              "      <td>1970.000000</td>\n",
              "      <td>0.000000</td>\n",
              "      <td>10.000000</td>\n",
              "      <td>0.000000e+00</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>25%</th>\n",
              "      <td>1.234568e+08</td>\n",
              "      <td>99985.000000</td>\n",
              "      <td>1982.000000</td>\n",
              "      <td>2505.750000</td>\n",
              "      <td>181.000000</td>\n",
              "      <td>5.003370e+05</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>50%</th>\n",
              "      <td>1.234568e+08</td>\n",
              "      <td>99990.000000</td>\n",
              "      <td>1995.000000</td>\n",
              "      <td>4994.000000</td>\n",
              "      <td>356.000000</td>\n",
              "      <td>1.335698e+06</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>75%</th>\n",
              "      <td>1.234568e+08</td>\n",
              "      <td>99995.000000</td>\n",
              "      <td>2007.000000</td>\n",
              "      <td>7451.500000</td>\n",
              "      <td>531.000000</td>\n",
              "      <td>2.711653e+06</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>max</th>\n",
              "      <td>1.234568e+08</td>\n",
              "      <td>99999.000000</td>\n",
              "      <td>2019.000000</td>\n",
              "      <td>9999.000000</td>\n",
              "      <td>700.000000</td>\n",
              "      <td>6.841580e+06</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ],
            "text/plain": [
              "            Account         Order  ...     UnitPrice    TotalPrice\n",
              "count  1.000000e+04  10000.000000  ...  10000.000000  1.000000e+04\n",
              "mean   1.234568e+08  99989.562900  ...    355.866600  1.773301e+06\n",
              "std    5.741156e+00      5.905551  ...    201.378478  1.540646e+06\n",
              "min    1.234568e+08  99980.000000  ...     10.000000  0.000000e+00\n",
              "25%    1.234568e+08  99985.000000  ...    181.000000  5.003370e+05\n",
              "50%    1.234568e+08  99990.000000  ...    356.000000  1.335698e+06\n",
              "75%    1.234568e+08  99995.000000  ...    531.000000  2.711653e+06\n",
              "max    1.234568e+08  99999.000000  ...    700.000000  6.841580e+06\n",
              "\n",
              "[8 rows x 6 columns]"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 15
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "wU5_yJnAtImC",
        "colab_type": "text"
      },
      "source": [
        "## Reshaping with Hierarchical Indexing"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "T3WyVk2JtHzj",
        "colab_type": "code",
        "outputId": "fd7b98d3-cdb7-48ba-c4b6-aca3448c4e12",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 142
        }
      },
      "source": [
        "data = np.arange(15).reshape((3,5))\n",
        "indexers = ['Rainfall', 'Humidity', 'Wind']\n",
        "dframe1 = pd.DataFrame(data, index=indexers, columns=['Bergen', 'Oslo', 'Trondheim', 'Stavanger', 'Kristiansand'])\n",
        "dframe1"
      ],
      "execution_count": 16,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>Bergen</th>\n",
              "      <th>Oslo</th>\n",
              "      <th>Trondheim</th>\n",
              "      <th>Stavanger</th>\n",
              "      <th>Kristiansand</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>Rainfall</th>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>2</td>\n",
              "      <td>3</td>\n",
              "      <td>4</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>Humidity</th>\n",
              "      <td>5</td>\n",
              "      <td>6</td>\n",
              "      <td>7</td>\n",
              "      <td>8</td>\n",
              "      <td>9</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>Wind</th>\n",
              "      <td>10</td>\n",
              "      <td>11</td>\n",
              "      <td>12</td>\n",
              "      <td>13</td>\n",
              "      <td>14</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ],
            "text/plain": [
              "          Bergen  Oslo  Trondheim  Stavanger  Kristiansand\n",
              "Rainfall       0     1          2          3             4\n",
              "Humidity       5     6          7          8             9\n",
              "Wind          10    11         12         13            14"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 16
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "eJusYeXfvjQj",
        "colab_type": "code",
        "outputId": "35cb96a5-7083-49d1-9c59-f013b0fea7bb",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 289
        }
      },
      "source": [
        "stacked = dframe1.stack()\n",
        "stacked"
      ],
      "execution_count": 17,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "Rainfall  Bergen           0\n",
              "          Oslo             1\n",
              "          Trondheim        2\n",
              "          Stavanger        3\n",
              "          Kristiansand     4\n",
              "Humidity  Bergen           5\n",
              "          Oslo             6\n",
              "          Trondheim        7\n",
              "          Stavanger        8\n",
              "          Kristiansand     9\n",
              "Wind      Bergen          10\n",
              "          Oslo            11\n",
              "          Trondheim       12\n",
              "          Stavanger       13\n",
              "          Kristiansand    14\n",
              "dtype: int64"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 17
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "gbjBsUq1vs_P",
        "colab_type": "code",
        "outputId": "ebd576b3-e098-4563-b849-52fc279e1440",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 142
        }
      },
      "source": [
        "stacked.unstack()"
      ],
      "execution_count": 18,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>Bergen</th>\n",
              "      <th>Oslo</th>\n",
              "      <th>Trondheim</th>\n",
              "      <th>Stavanger</th>\n",
              "      <th>Kristiansand</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>Rainfall</th>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>2</td>\n",
              "      <td>3</td>\n",
              "      <td>4</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>Humidity</th>\n",
              "      <td>5</td>\n",
              "      <td>6</td>\n",
              "      <td>7</td>\n",
              "      <td>8</td>\n",
              "      <td>9</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>Wind</th>\n",
              "      <td>10</td>\n",
              "      <td>11</td>\n",
              "      <td>12</td>\n",
              "      <td>13</td>\n",
              "      <td>14</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ],
            "text/plain": [
              "          Bergen  Oslo  Trondheim  Stavanger  Kristiansand\n",
              "Rainfall       0     1          2          3             4\n",
              "Humidity       5     6          7          8             9\n",
              "Wind          10    11         12         13            14"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 18
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "cBT2LtcKv5r-",
        "colab_type": "code",
        "outputId": "a7b68666-61f8-4d52-96b5-5f6d67735403",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 111
        }
      },
      "source": [
        "series1 = pd.Series([000, 111, 222, 333], index=['zeros','ones', 'twos', 'threes'])\n",
        "series2 = pd.Series([444, 555, 666], index=['fours', 'fives', 'sixs'])\n",
        "\n",
        "frame2 = pd.concat([series1, series2], keys=['Number1', 'Number2'])\n",
        "frame2.unstack()"
      ],
      "execution_count": 19,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>fives</th>\n",
              "      <th>fours</th>\n",
              "      <th>ones</th>\n",
              "      <th>sixs</th>\n",
              "      <th>threes</th>\n",
              "      <th>twos</th>\n",
              "      <th>zeros</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>Number1</th>\n",
              "      <td>NaN</td>\n",
              "      <td>NaN</td>\n",
              "      <td>111.0</td>\n",
              "      <td>NaN</td>\n",
              "      <td>333.0</td>\n",
              "      <td>222.0</td>\n",
              "      <td>0.0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>Number2</th>\n",
              "      <td>555.0</td>\n",
              "      <td>444.0</td>\n",
              "      <td>NaN</td>\n",
              "      <td>666.0</td>\n",
              "      <td>NaN</td>\n",
              "      <td>NaN</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ],
            "text/plain": [
              "         fives  fours   ones   sixs  threes   twos  zeros\n",
              "Number1    NaN    NaN  111.0    NaN   333.0  222.0    0.0\n",
              "Number2  555.0  444.0    NaN  666.0     NaN    NaN    NaN"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 19
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "sK21LWxU7_5d",
        "colab_type": "text"
      },
      "source": [
        "# Data deduplication"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "qQ5aZh3R8Cmh",
        "colab_type": "code",
        "outputId": "93df52b1-23f7-4381-c581-729b87e1777b",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 266
        }
      },
      "source": [
        "frame3 = pd.DataFrame({'column 1': ['Looping'] * 3 + ['Functions'] * 4, 'column 2': [10, 10, 22, 23, 23, 24, 24]})\n",
        "frame3"
      ],
      "execution_count": 20,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>column 1</th>\n",
              "      <th>column 2</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>Looping</td>\n",
              "      <td>10</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>Looping</td>\n",
              "      <td>10</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>Looping</td>\n",
              "      <td>22</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3</th>\n",
              "      <td>Functions</td>\n",
              "      <td>23</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>4</th>\n",
              "      <td>Functions</td>\n",
              "      <td>23</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>5</th>\n",
              "      <td>Functions</td>\n",
              "      <td>24</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>6</th>\n",
              "      <td>Functions</td>\n",
              "      <td>24</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ],
            "text/plain": [
              "    column 1  column 2\n",
              "0    Looping        10\n",
              "1    Looping        10\n",
              "2    Looping        22\n",
              "3  Functions        23\n",
              "4  Functions        23\n",
              "5  Functions        24\n",
              "6  Functions        24"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 20
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "Ptgbp7Lz-YhP",
        "colab_type": "code",
        "outputId": "e6a79780-fb1b-4125-f03b-215291a2ec68",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 153
        }
      },
      "source": [
        "frame3.duplicated()"
      ],
      "execution_count": 21,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "0    False\n",
              "1     True\n",
              "2    False\n",
              "3    False\n",
              "4     True\n",
              "5    False\n",
              "6     True\n",
              "dtype: bool"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 21
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "kGZwl8nZ-nAy",
        "colab_type": "code",
        "outputId": "eb07dc61-d557-4390-f785-91c4aaa3b111",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 173
        }
      },
      "source": [
        "frame4 = frame3.drop_duplicates()\n",
        "frame4"
      ],
      "execution_count": 22,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>column 1</th>\n",
              "      <th>column 2</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>Looping</td>\n",
              "      <td>10</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>Looping</td>\n",
              "      <td>22</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3</th>\n",
              "      <td>Functions</td>\n",
              "      <td>23</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>5</th>\n",
              "      <td>Functions</td>\n",
              "      <td>24</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ],
            "text/plain": [
              "    column 1  column 2\n",
              "0    Looping        10\n",
              "2    Looping        22\n",
              "3  Functions        23\n",
              "5  Functions        24"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 22
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "Tczy4Zo4-zj1",
        "colab_type": "code",
        "outputId": "9eb04678-ff7a-48c0-89a2-a1eca062e665",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 173
        }
      },
      "source": [
        "frame3['column 3'] = range(7)\n",
        "frame5 = frame3.drop_duplicates(['column 2'])\n",
        "frame5"
      ],
      "execution_count": 23,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>column 1</th>\n",
              "      <th>column 2</th>\n",
              "      <th>column 3</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>Looping</td>\n",
              "      <td>10</td>\n",
              "      <td>0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>Looping</td>\n",
              "      <td>22</td>\n",
              "      <td>2</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3</th>\n",
              "      <td>Functions</td>\n",
              "      <td>23</td>\n",
              "      <td>3</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>5</th>\n",
              "      <td>Functions</td>\n",
              "      <td>24</td>\n",
              "      <td>5</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ],
            "text/plain": [
              "    column 1  column 2  column 3\n",
              "0    Looping        10         0\n",
              "2    Looping        22         2\n",
              "3  Functions        23         3\n",
              "5  Functions        24         5"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 23
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "V_IIMFO8nUOP",
        "colab_type": "text"
      },
      "source": [
        "# Replacing values"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "QAg3Cvs4pbMg",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "import numpy as np\n"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "tGrxoEnomux6",
        "colab_type": "code",
        "outputId": "816c0138-9471-4f0d-bba8-ef014a5354d7",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 328
        }
      },
      "source": [
        "replaceFrame = pd.DataFrame({'column 1': [200., 3000., -786., 3000., 234., 444., -786., 332., 3332. ], 'column 2': range(9)})\n",
        "replaceFrame.replace(to_replace =-786, value= np.nan)\n"
      ],
      "execution_count": 25,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>column 1</th>\n",
              "      <th>column 2</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>200.0</td>\n",
              "      <td>0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>3000.0</td>\n",
              "      <td>1</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>NaN</td>\n",
              "      <td>2</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3</th>\n",
              "      <td>3000.0</td>\n",
              "      <td>3</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>4</th>\n",
              "      <td>234.0</td>\n",
              "      <td>4</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>5</th>\n",
              "      <td>444.0</td>\n",
              "      <td>5</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>6</th>\n",
              "      <td>NaN</td>\n",
              "      <td>6</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>7</th>\n",
              "      <td>332.0</td>\n",
              "      <td>7</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>8</th>\n",
              "      <td>3332.0</td>\n",
              "      <td>8</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ],
            "text/plain": [
              "   column 1  column 2\n",
              "0     200.0         0\n",
              "1    3000.0         1\n",
              "2       NaN         2\n",
              "3    3000.0         3\n",
              "4     234.0         4\n",
              "5     444.0         5\n",
              "6       NaN         6\n",
              "7     332.0         7\n",
              "8    3332.0         8"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 25
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "IgEE2Y6QqS1e",
        "colab_type": "code",
        "outputId": "0665e4ee-5783-43ed-b19b-ad2384233266",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 328
        }
      },
      "source": [
        "replaceFrame = pd.DataFrame({'column 1': [200., 3000., -786., 3000., 234., 444., -786., 332., 3332. ], 'column 2': range(9)})\n",
        "replaceFrame.replace(to_replace =[-786, 0], value= [np.nan, 2])\n"
      ],
      "execution_count": 26,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>column 1</th>\n",
              "      <th>column 2</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>200.0</td>\n",
              "      <td>2</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>3000.0</td>\n",
              "      <td>1</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>NaN</td>\n",
              "      <td>2</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3</th>\n",
              "      <td>3000.0</td>\n",
              "      <td>3</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>4</th>\n",
              "      <td>234.0</td>\n",
              "      <td>4</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>5</th>\n",
              "      <td>444.0</td>\n",
              "      <td>5</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>6</th>\n",
              "      <td>NaN</td>\n",
              "      <td>6</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>7</th>\n",
              "      <td>332.0</td>\n",
              "      <td>7</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>8</th>\n",
              "      <td>3332.0</td>\n",
              "      <td>8</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ],
            "text/plain": [
              "   column 1  column 2\n",
              "0     200.0         2\n",
              "1    3000.0         1\n",
              "2       NaN         2\n",
              "3    3000.0         3\n",
              "4     234.0         4\n",
              "5     444.0         5\n",
              "6       NaN         6\n",
              "7     332.0         7\n",
              "8    3332.0         8"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 26
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "HNY_PNmcmcHg",
        "colab_type": "text"
      },
      "source": [
        "# Handling missing data"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "39Ww1TLcmfS7",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 204
        },
        "outputId": "ed86912f-119b-4d87-dfad-ae637a303027"
      },
      "source": [
        "data = np.arange(15, 30).reshape(5, 3)\n",
        "dfx = pd.DataFrame(data, index=['apple', 'banana', 'kiwi', 'grapes', 'mango'], columns=['store1', 'store2', 'store3'])\n",
        "dfx"
      ],
      "execution_count": 3,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>store1</th>\n",
              "      <th>store2</th>\n",
              "      <th>store3</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>apple</th>\n",
              "      <td>15</td>\n",
              "      <td>16</td>\n",
              "      <td>17</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>banana</th>\n",
              "      <td>18</td>\n",
              "      <td>19</td>\n",
              "      <td>20</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>kiwi</th>\n",
              "      <td>21</td>\n",
              "      <td>22</td>\n",
              "      <td>23</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>grapes</th>\n",
              "      <td>24</td>\n",
              "      <td>25</td>\n",
              "      <td>26</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>mango</th>\n",
              "      <td>27</td>\n",
              "      <td>28</td>\n",
              "      <td>29</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ],
            "text/plain": [
              "        store1  store2  store3\n",
              "apple       15      16      17\n",
              "banana      18      19      20\n",
              "kiwi        21      22      23\n",
              "grapes      24      25      26\n",
              "mango       27      28      29"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 3
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "5xIB7OoLnP6d",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 266
        },
        "outputId": "be61e1d6-542d-4836-947f-a2b7abd300f8"
      },
      "source": [
        "dfx['store4'] = np.nan\n",
        "dfx.loc['watermelon'] = np.arange(15, 19)\n",
        "dfx.loc['oranges'] = np.nan\n",
        "dfx['store5'] = np.nan\n",
        "dfx['store4']['apple'] = 20.\n",
        "dfx"
      ],
      "execution_count": 4,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>store1</th>\n",
              "      <th>store2</th>\n",
              "      <th>store3</th>\n",
              "      <th>store4</th>\n",
              "      <th>store5</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>apple</th>\n",
              "      <td>15.0</td>\n",
              "      <td>16.0</td>\n",
              "      <td>17.0</td>\n",
              "      <td>20.0</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>banana</th>\n",
              "      <td>18.0</td>\n",
              "      <td>19.0</td>\n",
              "      <td>20.0</td>\n",
              "      <td>NaN</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>kiwi</th>\n",
              "      <td>21.0</td>\n",
              "      <td>22.0</td>\n",
              "      <td>23.0</td>\n",
              "      <td>NaN</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>grapes</th>\n",
              "      <td>24.0</td>\n",
              "      <td>25.0</td>\n",
              "      <td>26.0</td>\n",
              "      <td>NaN</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>mango</th>\n",
              "      <td>27.0</td>\n",
              "      <td>28.0</td>\n",
              "      <td>29.0</td>\n",
              "      <td>NaN</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>watermelon</th>\n",
              "      <td>15.0</td>\n",
              "      <td>16.0</td>\n",
              "      <td>17.0</td>\n",
              "      <td>18.0</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>oranges</th>\n",
              "      <td>NaN</td>\n",
              "      <td>NaN</td>\n",
              "      <td>NaN</td>\n",
              "      <td>NaN</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ],
            "text/plain": [
              "            store1  store2  store3  store4  store5\n",
              "apple         15.0    16.0    17.0    20.0     NaN\n",
              "banana        18.0    19.0    20.0     NaN     NaN\n",
              "kiwi          21.0    22.0    23.0     NaN     NaN\n",
              "grapes        24.0    25.0    26.0     NaN     NaN\n",
              "mango         27.0    28.0    29.0     NaN     NaN\n",
              "watermelon    15.0    16.0    17.0    18.0     NaN\n",
              "oranges        NaN     NaN     NaN     NaN     NaN"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 4
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "rmmnyON7n5Aw",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 266
        },
        "outputId": "92682fe9-b776-4c27-fb94-87f140edec03"
      },
      "source": [
        "dfx.isnull()"
      ],
      "execution_count": 97,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>store1</th>\n",
              "      <th>store2</th>\n",
              "      <th>store3</th>\n",
              "      <th>store4</th>\n",
              "      <th>store5</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>apple</th>\n",
              "      <td>False</td>\n",
              "      <td>False</td>\n",
              "      <td>False</td>\n",
              "      <td>False</td>\n",
              "      <td>True</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>banana</th>\n",
              "      <td>False</td>\n",
              "      <td>False</td>\n",
              "      <td>False</td>\n",
              "      <td>True</td>\n",
              "      <td>True</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>kiwi</th>\n",
              "      <td>False</td>\n",
              "      <td>False</td>\n",
              "      <td>False</td>\n",
              "      <td>True</td>\n",
              "      <td>True</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>grapes</th>\n",
              "      <td>False</td>\n",
              "      <td>False</td>\n",
              "      <td>False</td>\n",
              "      <td>True</td>\n",
              "      <td>True</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>mango</th>\n",
              "      <td>False</td>\n",
              "      <td>False</td>\n",
              "      <td>False</td>\n",
              "      <td>True</td>\n",
              "      <td>True</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>watermelon</th>\n",
              "      <td>False</td>\n",
              "      <td>False</td>\n",
              "      <td>False</td>\n",
              "      <td>False</td>\n",
              "      <td>True</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>oranges</th>\n",
              "      <td>True</td>\n",
              "      <td>True</td>\n",
              "      <td>True</td>\n",
              "      <td>True</td>\n",
              "      <td>True</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ],
            "text/plain": [
              "            store1  store2  store3  store4  store5\n",
              "apple        False   False   False   False    True\n",
              "banana       False   False   False    True    True\n",
              "kiwi         False   False   False    True    True\n",
              "grapes       False   False   False    True    True\n",
              "mango        False   False   False    True    True\n",
              "watermelon   False   False   False   False    True\n",
              "oranges       True    True    True    True    True"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 97
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "cRxkzSDVoRdQ",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 266
        },
        "outputId": "343d1a39-d6e7-415b-cf4e-54886ceca871"
      },
      "source": [
        "dfx.notnull()"
      ],
      "execution_count": 98,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>store1</th>\n",
              "      <th>store2</th>\n",
              "      <th>store3</th>\n",
              "      <th>store4</th>\n",
              "      <th>store5</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>apple</th>\n",
              "      <td>True</td>\n",
              "      <td>True</td>\n",
              "      <td>True</td>\n",
              "      <td>True</td>\n",
              "      <td>False</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>banana</th>\n",
              "      <td>True</td>\n",
              "      <td>True</td>\n",
              "      <td>True</td>\n",
              "      <td>False</td>\n",
              "      <td>False</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>kiwi</th>\n",
              "      <td>True</td>\n",
              "      <td>True</td>\n",
              "      <td>True</td>\n",
              "      <td>False</td>\n",
              "      <td>False</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>grapes</th>\n",
              "      <td>True</td>\n",
              "      <td>True</td>\n",
              "      <td>True</td>\n",
              "      <td>False</td>\n",
              "      <td>False</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>mango</th>\n",
              "      <td>True</td>\n",
              "      <td>True</td>\n",
              "      <td>True</td>\n",
              "      <td>False</td>\n",
              "      <td>False</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>watermelon</th>\n",
              "      <td>True</td>\n",
              "      <td>True</td>\n",
              "      <td>True</td>\n",
              "      <td>True</td>\n",
              "      <td>False</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>oranges</th>\n",
              "      <td>False</td>\n",
              "      <td>False</td>\n",
              "      <td>False</td>\n",
              "      <td>False</td>\n",
              "      <td>False</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ],
            "text/plain": [
              "            store1  store2  store3  store4  store5\n",
              "apple         True    True    True    True   False\n",
              "banana        True    True    True   False   False\n",
              "kiwi          True    True    True   False   False\n",
              "grapes        True    True    True   False   False\n",
              "mango         True    True    True   False   False\n",
              "watermelon    True    True    True    True   False\n",
              "oranges      False   False   False   False   False"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 98
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "jX7hvqfHn895",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 119
        },
        "outputId": "f27095b4-98ba-430b-b54a-9741d5294efd"
      },
      "source": [
        "dfx.isnull().sum()"
      ],
      "execution_count": 99,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "store1    1\n",
              "store2    1\n",
              "store3    1\n",
              "store4    5\n",
              "store5    7\n",
              "dtype: int64"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 99
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "zOnkTx3QoD_J",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 34
        },
        "outputId": "d0b94ab8-71c2-4222-c6a0-16bc6ff5d6e7"
      },
      "source": [
        "dfx.isnull().sum().sum()"
      ],
      "execution_count": 100,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "15"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 100
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "Av3zejZKoIV1",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 119
        },
        "outputId": "036ca1dd-e939-49c2-f5eb-0d6674c034cb"
      },
      "source": [
        "dfx.count()"
      ],
      "execution_count": 101,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "store1    6\n",
              "store2    6\n",
              "store3    6\n",
              "store4    2\n",
              "store5    0\n",
              "dtype: int64"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 101
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "iEFQpdEboWzT",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 68
        },
        "outputId": "b73aa208-73ed-416d-fc79-9c1aa58f3c13"
      },
      "source": [
        "dfx.store4[dfx.store4.notnull()]"
      ],
      "execution_count": 102,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "apple         20.0\n",
              "watermelon    18.0\n",
              "Name: store4, dtype: float64"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 102
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "K7t99jEDpd4t",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 68
        },
        "outputId": "7543a2b9-f0e4-487d-b623-7c674034dcb1"
      },
      "source": [
        "dfx.store4.dropna()\n"
      ],
      "execution_count": 105,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "apple         20.0\n",
              "watermelon    18.0\n",
              "Name: store4, dtype: float64"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 105
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "GcEKe8kgptUp",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 49
        },
        "outputId": "c2a9e8bc-77f1-469b-cbfb-400b1835a322"
      },
      "source": [
        "dfx.dropna()"
      ],
      "execution_count": 106,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>store1</th>\n",
              "      <th>store2</th>\n",
              "      <th>store3</th>\n",
              "      <th>store4</th>\n",
              "      <th>store5</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ],
            "text/plain": [
              "Empty DataFrame\n",
              "Columns: [store1, store2, store3, store4, store5]\n",
              "Index: []"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 106
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "v6FoQukXp14V",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 235
        },
        "outputId": "1325a169-4c64-4981-b0ef-7d43c5d5d68a"
      },
      "source": [
        "dfx.dropna(how='all')"
      ],
      "execution_count": 107,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>store1</th>\n",
              "      <th>store2</th>\n",
              "      <th>store3</th>\n",
              "      <th>store4</th>\n",
              "      <th>store5</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>apple</th>\n",
              "      <td>15.0</td>\n",
              "      <td>16.0</td>\n",
              "      <td>17.0</td>\n",
              "      <td>20.0</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>banana</th>\n",
              "      <td>18.0</td>\n",
              "      <td>19.0</td>\n",
              "      <td>20.0</td>\n",
              "      <td>NaN</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>kiwi</th>\n",
              "      <td>21.0</td>\n",
              "      <td>22.0</td>\n",
              "      <td>23.0</td>\n",
              "      <td>NaN</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>grapes</th>\n",
              "      <td>24.0</td>\n",
              "      <td>25.0</td>\n",
              "      <td>26.0</td>\n",
              "      <td>NaN</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>mango</th>\n",
              "      <td>27.0</td>\n",
              "      <td>28.0</td>\n",
              "      <td>29.0</td>\n",
              "      <td>NaN</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>watermelon</th>\n",
              "      <td>15.0</td>\n",
              "      <td>16.0</td>\n",
              "      <td>17.0</td>\n",
              "      <td>18.0</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ],
            "text/plain": [
              "            store1  store2  store3  store4  store5\n",
              "apple         15.0    16.0    17.0    20.0     NaN\n",
              "banana        18.0    19.0    20.0     NaN     NaN\n",
              "kiwi          21.0    22.0    23.0     NaN     NaN\n",
              "grapes        24.0    25.0    26.0     NaN     NaN\n",
              "mango         27.0    28.0    29.0     NaN     NaN\n",
              "watermelon    15.0    16.0    17.0    18.0     NaN"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 107
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "_p-FcoMTqBPR",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 266
        },
        "outputId": "35b013f4-6da8-4d07-fa8c-ca2ab787702c"
      },
      "source": [
        "dfx.dropna(how='all', axis=1)"
      ],
      "execution_count": 108,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>store1</th>\n",
              "      <th>store2</th>\n",
              "      <th>store3</th>\n",
              "      <th>store4</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>apple</th>\n",
              "      <td>15.0</td>\n",
              "      <td>16.0</td>\n",
              "      <td>17.0</td>\n",
              "      <td>20.0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>banana</th>\n",
              "      <td>18.0</td>\n",
              "      <td>19.0</td>\n",
              "      <td>20.0</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>kiwi</th>\n",
              "      <td>21.0</td>\n",
              "      <td>22.0</td>\n",
              "      <td>23.0</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>grapes</th>\n",
              "      <td>24.0</td>\n",
              "      <td>25.0</td>\n",
              "      <td>26.0</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>mango</th>\n",
              "      <td>27.0</td>\n",
              "      <td>28.0</td>\n",
              "      <td>29.0</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>watermelon</th>\n",
              "      <td>15.0</td>\n",
              "      <td>16.0</td>\n",
              "      <td>17.0</td>\n",
              "      <td>18.0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>oranges</th>\n",
              "      <td>NaN</td>\n",
              "      <td>NaN</td>\n",
              "      <td>NaN</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ],
            "text/plain": [
              "            store1  store2  store3  store4\n",
              "apple         15.0    16.0    17.0    20.0\n",
              "banana        18.0    19.0    20.0     NaN\n",
              "kiwi          21.0    22.0    23.0     NaN\n",
              "grapes        24.0    25.0    26.0     NaN\n",
              "mango         27.0    28.0    29.0     NaN\n",
              "watermelon    15.0    16.0    17.0    18.0\n",
              "oranges        NaN     NaN     NaN     NaN"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 108
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "OD-aF7lNqRaX",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 266
        },
        "outputId": "90409a08-edfa-4abd-e762-0ba9c2758d84"
      },
      "source": [
        "dfx2 = dfx.copy()\n",
        "dfx2.loc['oranges'].store1 = 0\n",
        "dfx2.loc['oranges'].store3 = 0\n",
        "dfx2"
      ],
      "execution_count": 110,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>store1</th>\n",
              "      <th>store2</th>\n",
              "      <th>store3</th>\n",
              "      <th>store4</th>\n",
              "      <th>store5</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>apple</th>\n",
              "      <td>15.0</td>\n",
              "      <td>16.0</td>\n",
              "      <td>17.0</td>\n",
              "      <td>20.0</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>banana</th>\n",
              "      <td>18.0</td>\n",
              "      <td>19.0</td>\n",
              "      <td>20.0</td>\n",
              "      <td>NaN</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>kiwi</th>\n",
              "      <td>21.0</td>\n",
              "      <td>22.0</td>\n",
              "      <td>23.0</td>\n",
              "      <td>NaN</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>grapes</th>\n",
              "      <td>24.0</td>\n",
              "      <td>25.0</td>\n",
              "      <td>26.0</td>\n",
              "      <td>NaN</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>mango</th>\n",
              "      <td>27.0</td>\n",
              "      <td>28.0</td>\n",
              "      <td>29.0</td>\n",
              "      <td>NaN</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>watermelon</th>\n",
              "      <td>15.0</td>\n",
              "      <td>16.0</td>\n",
              "      <td>17.0</td>\n",
              "      <td>18.0</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>oranges</th>\n",
              "      <td>0.0</td>\n",
              "      <td>NaN</td>\n",
              "      <td>0.0</td>\n",
              "      <td>NaN</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ],
            "text/plain": [
              "            store1  store2  store3  store4  store5\n",
              "apple         15.0    16.0    17.0    20.0     NaN\n",
              "banana        18.0    19.0    20.0     NaN     NaN\n",
              "kiwi          21.0    22.0    23.0     NaN     NaN\n",
              "grapes        24.0    25.0    26.0     NaN     NaN\n",
              "mango         27.0    28.0    29.0     NaN     NaN\n",
              "watermelon    15.0    16.0    17.0    18.0     NaN\n",
              "oranges        0.0     NaN     0.0     NaN     NaN"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 110
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "MQkyLWCRqj7g",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 266
        },
        "outputId": "81f42642-ae31-418c-91e8-312f89bd82ce"
      },
      "source": [
        "dfx2.dropna(how='any', axis=1)"
      ],
      "execution_count": 111,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>store1</th>\n",
              "      <th>store3</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>apple</th>\n",
              "      <td>15.0</td>\n",
              "      <td>17.0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>banana</th>\n",
              "      <td>18.0</td>\n",
              "      <td>20.0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>kiwi</th>\n",
              "      <td>21.0</td>\n",
              "      <td>23.0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>grapes</th>\n",
              "      <td>24.0</td>\n",
              "      <td>26.0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>mango</th>\n",
              "      <td>27.0</td>\n",
              "      <td>29.0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>watermelon</th>\n",
              "      <td>15.0</td>\n",
              "      <td>17.0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>oranges</th>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ],
            "text/plain": [
              "            store1  store3\n",
              "apple         15.0    17.0\n",
              "banana        18.0    20.0\n",
              "kiwi          21.0    23.0\n",
              "grapes        24.0    26.0\n",
              "mango         27.0    29.0\n",
              "watermelon    15.0    17.0\n",
              "oranges        0.0     0.0"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 111
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "e3t6-Yiuqqz4",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 266
        },
        "outputId": "73972fa2-fe0a-4b38-f166-50fb7f2afb7f"
      },
      "source": [
        "dfx.dropna(thresh=5, axis=1)\n"
      ],
      "execution_count": 112,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>store1</th>\n",
              "      <th>store2</th>\n",
              "      <th>store3</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>apple</th>\n",
              "      <td>15.0</td>\n",
              "      <td>16.0</td>\n",
              "      <td>17.0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>banana</th>\n",
              "      <td>18.0</td>\n",
              "      <td>19.0</td>\n",
              "      <td>20.0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>kiwi</th>\n",
              "      <td>21.0</td>\n",
              "      <td>22.0</td>\n",
              "      <td>23.0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>grapes</th>\n",
              "      <td>24.0</td>\n",
              "      <td>25.0</td>\n",
              "      <td>26.0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>mango</th>\n",
              "      <td>27.0</td>\n",
              "      <td>28.0</td>\n",
              "      <td>29.0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>watermelon</th>\n",
              "      <td>15.0</td>\n",
              "      <td>16.0</td>\n",
              "      <td>17.0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>oranges</th>\n",
              "      <td>NaN</td>\n",
              "      <td>NaN</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ],
            "text/plain": [
              "            store1  store2  store3\n",
              "apple         15.0    16.0    17.0\n",
              "banana        18.0    19.0    20.0\n",
              "kiwi          21.0    22.0    23.0\n",
              "grapes        24.0    25.0    26.0\n",
              "mango         27.0    28.0    29.0\n",
              "watermelon    15.0    16.0    17.0\n",
              "oranges        NaN     NaN     NaN"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 112
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "5yPGxdb_rI32",
        "colab_type": "text"
      },
      "source": [
        "## NaN values in mathematical operations"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "zZvjkIEuq4Z8",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 34
        },
        "outputId": "32d50032-43a5-42e3-fc85-85ddee946358"
      },
      "source": [
        "ar1 = np.array([100, 200, np.nan, 300])\n",
        "ser1 = pd.Series(ar1)\n",
        "\n",
        "ar1.mean(), ser1.mean()"
      ],
      "execution_count": 5,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "(nan, 200.0)"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 5
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "YIwdqe7mrr9w",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 34
        },
        "outputId": "daffb467-f2b1-4907-ada8-3b124c847ab6"
      },
      "source": [
        "ser2 = dfx.store4\n",
        "ser2.sum()"
      ],
      "execution_count": 7,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "38.0"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 7
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "7d3AIK2ZsJ9Q",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 34
        },
        "outputId": "6678a388-9c5c-4bab-b3f4-ec11d3f49416"
      },
      "source": [
        "ser2.mean()"
      ],
      "execution_count": 8,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "19.0"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 8
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "xR151fYmsPw9",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 153
        },
        "outputId": "47dad46c-dd36-4556-8c99-77bd7a4f0df2"
      },
      "source": [
        "ser2.cumsum()"
      ],
      "execution_count": 9,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "apple         20.0\n",
              "banana         NaN\n",
              "kiwi           NaN\n",
              "grapes         NaN\n",
              "mango          NaN\n",
              "watermelon    38.0\n",
              "oranges        NaN\n",
              "Name: store4, dtype: float64"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 9
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "dLGUzar9sVlp",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 153
        },
        "outputId": "b5d30f48-2a91-4b68-df60-43b077f1764d"
      },
      "source": [
        "dfx.store4 + 1"
      ],
      "execution_count": 10,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "apple         21.0\n",
              "banana         NaN\n",
              "kiwi           NaN\n",
              "grapes         NaN\n",
              "mango          NaN\n",
              "watermelon    19.0\n",
              "oranges        NaN\n",
              "Name: store4, dtype: float64"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 10
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "1lwepowxsa0Z",
        "colab_type": "text"
      },
      "source": [
        "## Filling in missing data\n"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "eDxqlyzQscvF",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 266
        },
        "outputId": "a9bee2bc-4c25-4305-902a-be0790349a06"
      },
      "source": [
        "filledDf = dfx.fillna(0)\n",
        "filledDf"
      ],
      "execution_count": 12,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>store1</th>\n",
              "      <th>store2</th>\n",
              "      <th>store3</th>\n",
              "      <th>store4</th>\n",
              "      <th>store5</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>apple</th>\n",
              "      <td>15.0</td>\n",
              "      <td>16.0</td>\n",
              "      <td>17.0</td>\n",
              "      <td>20.0</td>\n",
              "      <td>0.0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>banana</th>\n",
              "      <td>18.0</td>\n",
              "      <td>19.0</td>\n",
              "      <td>20.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>kiwi</th>\n",
              "      <td>21.0</td>\n",
              "      <td>22.0</td>\n",
              "      <td>23.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>grapes</th>\n",
              "      <td>24.0</td>\n",
              "      <td>25.0</td>\n",
              "      <td>26.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>mango</th>\n",
              "      <td>27.0</td>\n",
              "      <td>28.0</td>\n",
              "      <td>29.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>watermelon</th>\n",
              "      <td>15.0</td>\n",
              "      <td>16.0</td>\n",
              "      <td>17.0</td>\n",
              "      <td>18.0</td>\n",
              "      <td>0.0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>oranges</th>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "      <td>0.0</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ],
            "text/plain": [
              "            store1  store2  store3  store4  store5\n",
              "apple         15.0    16.0    17.0    20.0     0.0\n",
              "banana        18.0    19.0    20.0     0.0     0.0\n",
              "kiwi          21.0    22.0    23.0     0.0     0.0\n",
              "grapes        24.0    25.0    26.0     0.0     0.0\n",
              "mango         27.0    28.0    29.0     0.0     0.0\n",
              "watermelon    15.0    16.0    17.0    18.0     0.0\n",
              "oranges        0.0     0.0     0.0     0.0     0.0"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 12
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "c6gD2LamslI1",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 119
        },
        "outputId": "68a0526e-b80e-40b3-e352-9eb4f5a089fd"
      },
      "source": [
        "dfx.mean()"
      ],
      "execution_count": 16,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "store1    20.0\n",
              "store2    21.0\n",
              "store3    22.0\n",
              "store4    19.0\n",
              "store5     NaN\n",
              "dtype: float64"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 16
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "WlRGX4sBsz77",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 119
        },
        "outputId": "0f5c387a-dfa2-4678-c471-6d6b10a5a5e2"
      },
      "source": [
        "filledDf.mean()"
      ],
      "execution_count": 17,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "store1    17.142857\n",
              "store2    18.000000\n",
              "store3    18.857143\n",
              "store4     5.428571\n",
              "store5     0.000000\n",
              "dtype: float64"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 17
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "zCUfxrM8tHUv",
        "colab_type": "text"
      },
      "source": [
        "## Forward and backward filling of the missing values"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "UgFKn16ys36G",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 153
        },
        "outputId": "edb9d04a-c5bc-4578-a2c1-665823d944b0"
      },
      "source": [
        "dfx.store4.fillna(method='ffill')"
      ],
      "execution_count": 18,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "apple         20.0\n",
              "banana        20.0\n",
              "kiwi          20.0\n",
              "grapes        20.0\n",
              "mango         20.0\n",
              "watermelon    18.0\n",
              "oranges       18.0\n",
              "Name: store4, dtype: float64"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 18
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "Dtadk-EOtSvs",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 153
        },
        "outputId": "b8c96391-4f24-4ff9-8bdc-c88705544af5"
      },
      "source": [
        "dfx.store4.fillna(method='bfill')"
      ],
      "execution_count": 19,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "apple         20.0\n",
              "banana        18.0\n",
              "kiwi          18.0\n",
              "grapes        18.0\n",
              "mango         18.0\n",
              "watermelon    18.0\n",
              "oranges        NaN\n",
              "Name: store4, dtype: float64"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 19
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "EbC--IUftWKD",
        "colab_type": "text"
      },
      "source": [
        "## Filling with index labels\n"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "CpJq6vx0tiNu",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 85
        },
        "outputId": "67aa83c2-52db-488c-a2ca-6831954a8d98"
      },
      "source": [
        "to_fill = pd.Series([14, 23, 12], index=['apple', 'mango', 'oranges'])\n",
        "to_fill"
      ],
      "execution_count": 20,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "apple      14\n",
              "mango      23\n",
              "oranges    12\n",
              "dtype: int64"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 20
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "dLNp_tiKt7GX",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 153
        },
        "outputId": "5cf066cb-b1b8-4012-933f-47530999f366"
      },
      "source": [
        "dfx.store4.fillna(to_fill)\n"
      ],
      "execution_count": 21,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "apple         20.0\n",
              "banana         NaN\n",
              "kiwi           NaN\n",
              "grapes         NaN\n",
              "mango         23.0\n",
              "watermelon    18.0\n",
              "oranges       12.0\n",
              "Name: store4, dtype: float64"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 21
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "aGyjC6l_uHsV",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 266
        },
        "outputId": "8ec3e24d-1ff0-4aee-e1f4-159a5042f160"
      },
      "source": [
        "dfx.fillna(dfx.mean())"
      ],
      "execution_count": 23,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>store1</th>\n",
              "      <th>store2</th>\n",
              "      <th>store3</th>\n",
              "      <th>store4</th>\n",
              "      <th>store5</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>apple</th>\n",
              "      <td>15.0</td>\n",
              "      <td>16.0</td>\n",
              "      <td>17.0</td>\n",
              "      <td>20.0</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>banana</th>\n",
              "      <td>18.0</td>\n",
              "      <td>19.0</td>\n",
              "      <td>20.0</td>\n",
              "      <td>19.0</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>kiwi</th>\n",
              "      <td>21.0</td>\n",
              "      <td>22.0</td>\n",
              "      <td>23.0</td>\n",
              "      <td>19.0</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>grapes</th>\n",
              "      <td>24.0</td>\n",
              "      <td>25.0</td>\n",
              "      <td>26.0</td>\n",
              "      <td>19.0</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>mango</th>\n",
              "      <td>27.0</td>\n",
              "      <td>28.0</td>\n",
              "      <td>29.0</td>\n",
              "      <td>19.0</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>watermelon</th>\n",
              "      <td>15.0</td>\n",
              "      <td>16.0</td>\n",
              "      <td>17.0</td>\n",
              "      <td>18.0</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>oranges</th>\n",
              "      <td>20.0</td>\n",
              "      <td>21.0</td>\n",
              "      <td>22.0</td>\n",
              "      <td>19.0</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ],
            "text/plain": [
              "            store1  store2  store3  store4  store5\n",
              "apple         15.0    16.0    17.0    20.0     NaN\n",
              "banana        18.0    19.0    20.0    19.0     NaN\n",
              "kiwi          21.0    22.0    23.0    19.0     NaN\n",
              "grapes        24.0    25.0    26.0    19.0     NaN\n",
              "mango         27.0    28.0    29.0    19.0     NaN\n",
              "watermelon    15.0    16.0    17.0    18.0     NaN\n",
              "oranges       20.0    21.0    22.0    19.0     NaN"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 23
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "mdaffGmHuMxx",
        "colab_type": "text"
      },
      "source": [
        "## Interpolation of missing values"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "llLUU_d1uPoT",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 119
        },
        "outputId": "54be303d-4465-4e69-e6b8-5b35540d9fac"
      },
      "source": [
        "ser3 = pd.Series([100, np.nan, np.nan, np.nan, 292])\n",
        "ser3.interpolate()"
      ],
      "execution_count": 24,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "0    100.0\n",
              "1    148.0\n",
              "2    196.0\n",
              "3    244.0\n",
              "4    292.0\n",
              "dtype: float64"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 24
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "HH81nHrXvCbc",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 102
        },
        "outputId": "91e6c734-6816-49f0-9d1e-edfa3736b44f"
      },
      "source": [
        "from datetime import datetime\n",
        "ts = pd.Series([10, np.nan, np.nan, 9], \n",
        "               index=[datetime(2019, 1,1), \n",
        "                      datetime(2019, 2,1), \n",
        "                      datetime(2019, 3,1),\n",
        "                      datetime(2019, 5,1)])\n",
        "\n",
        "ts"
      ],
      "execution_count": 38,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "2019-01-01    10.0\n",
              "2019-02-01     NaN\n",
              "2019-03-01     NaN\n",
              "2019-05-01     9.0\n",
              "dtype: float64"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 38
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "NYf2f_tOwBDv",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 102
        },
        "outputId": "831a3204-17e8-46db-80cf-4d3428ec27bd"
      },
      "source": [
        "ts.interpolate()"
      ],
      "execution_count": 39,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "2019-01-01    10.000000\n",
              "2019-02-01     9.666667\n",
              "2019-03-01     9.333333\n",
              "2019-05-01     9.000000\n",
              "dtype: float64"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 39
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "3wYxBGUTwaE1",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 102
        },
        "outputId": "f3bf81cb-250f-4588-cc95-5ece560fd8e1"
      },
      "source": [
        "ts.interpolate(method='time')"
      ],
      "execution_count": 40,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "2019-01-01    10.000000\n",
              "2019-02-01     9.741667\n",
              "2019-03-01     9.508333\n",
              "2019-05-01     9.000000\n",
              "dtype: float64"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 40
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "JWStq05jt6E-",
        "colab_type": "text"
      },
      "source": [
        "# Renaming axis indexes"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "XclTPUwbt8U2",
        "colab_type": "code",
        "outputId": "532d9f0e-8d68-420e-a9d1-9ae9ae4bd379",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 142
        }
      },
      "source": [
        "data = np.arange(15).reshape((3,5))\n",
        "indexers = ['Rainfall', 'Humidity', 'Wind']\n",
        "dframe1 = pd.DataFrame(data, index=indexers, columns=['Bergen', 'Oslo', 'Trondheim', 'Stavanger', 'Kristiansand'])\n",
        "dframe1"
      ],
      "execution_count": 27,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>Bergen</th>\n",
              "      <th>Oslo</th>\n",
              "      <th>Trondheim</th>\n",
              "      <th>Stavanger</th>\n",
              "      <th>Kristiansand</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>Rainfall</th>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>2</td>\n",
              "      <td>3</td>\n",
              "      <td>4</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>Humidity</th>\n",
              "      <td>5</td>\n",
              "      <td>6</td>\n",
              "      <td>7</td>\n",
              "      <td>8</td>\n",
              "      <td>9</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>Wind</th>\n",
              "      <td>10</td>\n",
              "      <td>11</td>\n",
              "      <td>12</td>\n",
              "      <td>13</td>\n",
              "      <td>14</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ],
            "text/plain": [
              "          Bergen  Oslo  Trondheim  Stavanger  Kristiansand\n",
              "Rainfall       0     1          2          3             4\n",
              "Humidity       5     6          7          8             9\n",
              "Wind          10    11         12         13            14"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 27
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "O0Qv2t4kuD8x",
        "colab_type": "code",
        "outputId": "e283cb88-f281-45ae-e751-c0475b98726e",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 142
        }
      },
      "source": [
        "# Say, you want to transform the index terms to capital letter. \n",
        "dframe1.index = dframe1.index.map(str.upper)\n",
        "dframe1"
      ],
      "execution_count": 28,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>Bergen</th>\n",
              "      <th>Oslo</th>\n",
              "      <th>Trondheim</th>\n",
              "      <th>Stavanger</th>\n",
              "      <th>Kristiansand</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>RAINFALL</th>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>2</td>\n",
              "      <td>3</td>\n",
              "      <td>4</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>HUMIDITY</th>\n",
              "      <td>5</td>\n",
              "      <td>6</td>\n",
              "      <td>7</td>\n",
              "      <td>8</td>\n",
              "      <td>9</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>WIND</th>\n",
              "      <td>10</td>\n",
              "      <td>11</td>\n",
              "      <td>12</td>\n",
              "      <td>13</td>\n",
              "      <td>14</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ],
            "text/plain": [
              "          Bergen  Oslo  Trondheim  Stavanger  Kristiansand\n",
              "RAINFALL       0     1          2          3             4\n",
              "HUMIDITY       5     6          7          8             9\n",
              "WIND          10    11         12         13            14"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 28
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "Bry9nqFduoG3",
        "colab_type": "code",
        "outputId": "a8b0ab83-dfd9-4254-8a86-a5a8f685e17b",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 142
        }
      },
      "source": [
        "dframe1.rename(index=str.title, columns=str.upper)"
      ],
      "execution_count": 29,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>BERGEN</th>\n",
              "      <th>OSLO</th>\n",
              "      <th>TRONDHEIM</th>\n",
              "      <th>STAVANGER</th>\n",
              "      <th>KRISTIANSAND</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>Rainfall</th>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>2</td>\n",
              "      <td>3</td>\n",
              "      <td>4</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>Humidity</th>\n",
              "      <td>5</td>\n",
              "      <td>6</td>\n",
              "      <td>7</td>\n",
              "      <td>8</td>\n",
              "      <td>9</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>Wind</th>\n",
              "      <td>10</td>\n",
              "      <td>11</td>\n",
              "      <td>12</td>\n",
              "      <td>13</td>\n",
              "      <td>14</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ],
            "text/plain": [
              "          BERGEN  OSLO  TRONDHEIM  STAVANGER  KRISTIANSAND\n",
              "Rainfall       0     1          2          3             4\n",
              "Humidity       5     6          7          8             9\n",
              "Wind          10    11         12         13            14"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 29
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "Ihbm7F0po4AI",
        "colab_type": "text"
      },
      "source": [
        "# Discretization and binning\n"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "nmXviJEMo7Po",
        "colab_type": "code",
        "outputId": "5bb892e1-3d7c-49a7-e044-84ed4490d467",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 68
        }
      },
      "source": [
        "import pandas as pd\n",
        "\n",
        "height =  [120, 122, 125, 127, 121, 123, 137, 131, 161, 145, 141, 132]\n",
        "\n",
        "bins = [118, 125, 135, 160, 200]\n",
        "\n",
        "category = pd.cut(height, bins)\n",
        "\n",
        "category"
      ],
      "execution_count": 30,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "[(118, 125], (118, 125], (118, 125], (125, 135], (118, 125], ..., (125, 135], (160, 200], (135, 160], (135, 160], (125, 135]]\n",
              "Length: 12\n",
              "Categories (4, interval[int64]): [(118, 125] < (125, 135] < (135, 160] < (160, 200]]"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 30
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "TBUhvCRkBzej",
        "colab_type": "code",
        "outputId": "a3af0c0a-19cb-4942-c666-f90bc673d8c0",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 102
        }
      },
      "source": [
        "pd.value_counts(category)"
      ],
      "execution_count": 31,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "(118, 125]    5\n",
              "(135, 160]    3\n",
              "(125, 135]    3\n",
              "(160, 200]    1\n",
              "dtype: int64"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 31
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "_g7NDEETCBgJ",
        "colab_type": "code",
        "outputId": "752c7e92-19c1-4a1e-d413-0bd9a8861b16",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 68
        }
      },
      "source": [
        "category2 = pd.cut(height, [118, 126, 136, 161, 200], right=False)\n",
        "\n",
        "category2"
      ],
      "execution_count": 32,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "[[118, 126), [118, 126), [118, 126), [126, 136), [118, 126), ..., [126, 136), [161, 200), [136, 161), [136, 161), [126, 136)]\n",
              "Length: 12\n",
              "Categories (4, interval[int64]): [[118, 126) < [126, 136) < [136, 161) < [161, 200)]"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 32
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "2cz187zECbjJ",
        "colab_type": "code",
        "outputId": "b1a5303c-93a3-41e3-b725-cd3e5590b326",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 68
        }
      },
      "source": [
        "bin_names = ['Short Height', 'Averge height', 'Good Height', 'Taller']\n",
        "pd.cut(height, bins, labels=bin_names)"
      ],
      "execution_count": 33,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "[Short Height, Short Height, Short Height, Averge height, Short Height, ..., Averge height, Taller, Good Height, Good Height, Averge height]\n",
              "Length: 12\n",
              "Categories (4, object): [Short Height < Averge height < Good Height < Taller]"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 33
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "FGZHymZRDSPf",
        "colab_type": "code",
        "outputId": "1e39c135-33cc-4c98-aea4-87e4564a711e",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 85
        }
      },
      "source": [
        "# Number of bins as integer\n",
        "import numpy as np\n",
        "\n",
        "pd.cut(np.random.rand(40), 5, precision=2)\n"
      ],
      "execution_count": 34,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "[(0.21, 0.41], (0.21, 0.41], (0.79, 0.98], (0.02, 0.21], (0.79, 0.98], ..., (0.41, 0.6], (0.02, 0.21], (0.6, 0.79], (0.02, 0.21], (0.6, 0.79]]\n",
              "Length: 40\n",
              "Categories (5, interval[float64]): [(0.02, 0.21] < (0.21, 0.41] < (0.41, 0.6] < (0.6, 0.79] <\n",
              "                                    (0.79, 0.98]]"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 34
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "T7ujAia3DpXt",
        "colab_type": "code",
        "outputId": "cee7ac3a-2b7e-4e4a-92ec-dc69950d0eb2",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 88
        }
      },
      "source": [
        "randomNumbers = np.random.rand(2000)\n",
        "category3 = pd.qcut(randomNumbers, 4) # cut into quartiles\n",
        "category3"
      ],
      "execution_count": 35,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "[(0.502, 0.758], (0.758, 1.0], (0.502, 0.758], (0.758, 1.0], (-0.00013600000000000005, 0.239], ..., (0.239, 0.502], (0.239, 0.502], (0.239, 0.502], (0.502, 0.758], (0.758, 1.0]]\n",
              "Length: 2000\n",
              "Categories (4, interval[float64]): [(-0.00013600000000000005, 0.239] < (0.239, 0.502] < (0.502, 0.758] < (0.758, 1.0]]"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 35
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "a-sYRwOYECME",
        "colab_type": "code",
        "outputId": "3c3c6b76-e93f-4528-b857-551befa8a6e8",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 102
        }
      },
      "source": [
        "pd.value_counts(category3)"
      ],
      "execution_count": 36,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "(0.758, 1.0]                        500\n",
              "(0.502, 0.758]                      500\n",
              "(0.239, 0.502]                      500\n",
              "(-0.00013600000000000005, 0.239]    500\n",
              "dtype: int64"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 36
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "8ZN9C71dSyrz",
        "colab_type": "code",
        "outputId": "b870424e-9514-4233-b4bc-0284ab4a8d0b",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 88
        }
      },
      "source": [
        "pd.qcut(randomNumbers, [0, 0.3, 0.5, 0.7, 1.0])"
      ],
      "execution_count": 37,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "[(0.502, 0.709], (0.709, 1.0], (0.502, 0.709], (0.709, 1.0], (-0.00013600000000000005, 0.291], ..., (0.291, 0.502], (0.291, 0.502], (0.291, 0.502], (0.502, 0.709], (0.709, 1.0]]\n",
              "Length: 2000\n",
              "Categories (4, interval[float64]): [(-0.00013600000000000005, 0.291] < (0.291, 0.502] < (0.502, 0.709] < (0.709, 1.0]]"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 37
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "jhUjAjKKb91c",
        "colab_type": "code",
        "outputId": "88a5243a-380b-4d05-e2e1-e9cfebcd9fd4",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 359
        }
      },
      "source": [
        "df = pd.read_csv('https://raw.githubusercontent.com/PacktPublishing/hands-on-exploratory-data-analysis-with-python/master/Chapter%204/sales.csv')\n",
        "df.head(10)"
      ],
      "execution_count": 38,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>Account</th>\n",
              "      <th>Company</th>\n",
              "      <th>Order</th>\n",
              "      <th>SKU</th>\n",
              "      <th>Country</th>\n",
              "      <th>Year</th>\n",
              "      <th>Quantity</th>\n",
              "      <th>UnitPrice</th>\n",
              "      <th>transactionComplete</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>123456779</td>\n",
              "      <td>Kulas Inc</td>\n",
              "      <td>99985</td>\n",
              "      <td>s9-supercomputer</td>\n",
              "      <td>Aruba</td>\n",
              "      <td>1981</td>\n",
              "      <td>5148</td>\n",
              "      <td>545</td>\n",
              "      <td>False</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>123456784</td>\n",
              "      <td>GitHub</td>\n",
              "      <td>99986</td>\n",
              "      <td>s4-supercomputer</td>\n",
              "      <td>Brazil</td>\n",
              "      <td>2001</td>\n",
              "      <td>3262</td>\n",
              "      <td>383</td>\n",
              "      <td>False</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>123456782</td>\n",
              "      <td>Kulas Inc</td>\n",
              "      <td>99990</td>\n",
              "      <td>s10-supercomputer</td>\n",
              "      <td>Montserrat</td>\n",
              "      <td>1973</td>\n",
              "      <td>9119</td>\n",
              "      <td>407</td>\n",
              "      <td>True</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3</th>\n",
              "      <td>123456783</td>\n",
              "      <td>My SQ Man</td>\n",
              "      <td>99999</td>\n",
              "      <td>s1-supercomputer</td>\n",
              "      <td>El Salvador</td>\n",
              "      <td>2015</td>\n",
              "      <td>3097</td>\n",
              "      <td>615</td>\n",
              "      <td>False</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>4</th>\n",
              "      <td>123456787</td>\n",
              "      <td>ABC Dogma</td>\n",
              "      <td>99996</td>\n",
              "      <td>s6-supercomputer</td>\n",
              "      <td>Poland</td>\n",
              "      <td>1970</td>\n",
              "      <td>3356</td>\n",
              "      <td>91</td>\n",
              "      <td>True</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>5</th>\n",
              "      <td>123456778</td>\n",
              "      <td>Super Sexy Dingo</td>\n",
              "      <td>99996</td>\n",
              "      <td>s9-supercomputer</td>\n",
              "      <td>Costa Rica</td>\n",
              "      <td>2004</td>\n",
              "      <td>2474</td>\n",
              "      <td>136</td>\n",
              "      <td>True</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>6</th>\n",
              "      <td>123456783</td>\n",
              "      <td>ABC Dogma</td>\n",
              "      <td>99981</td>\n",
              "      <td>s11-supercomputer</td>\n",
              "      <td>Spain</td>\n",
              "      <td>2006</td>\n",
              "      <td>4081</td>\n",
              "      <td>195</td>\n",
              "      <td>False</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>7</th>\n",
              "      <td>123456785</td>\n",
              "      <td>ABC Dogma</td>\n",
              "      <td>99998</td>\n",
              "      <td>s9-supercomputer</td>\n",
              "      <td>Belarus</td>\n",
              "      <td>2015</td>\n",
              "      <td>6576</td>\n",
              "      <td>603</td>\n",
              "      <td>False</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>8</th>\n",
              "      <td>123456778</td>\n",
              "      <td>Loolo INC</td>\n",
              "      <td>99997</td>\n",
              "      <td>s8-supercomputer</td>\n",
              "      <td>Mauritius</td>\n",
              "      <td>1999</td>\n",
              "      <td>2460</td>\n",
              "      <td>36</td>\n",
              "      <td>False</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>9</th>\n",
              "      <td>123456775</td>\n",
              "      <td>Kulas Inc</td>\n",
              "      <td>99997</td>\n",
              "      <td>s7-supercomputer</td>\n",
              "      <td>French Guiana</td>\n",
              "      <td>2004</td>\n",
              "      <td>1831</td>\n",
              "      <td>664</td>\n",
              "      <td>True</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ],
            "text/plain": [
              "     Account           Company  Order  ... Quantity UnitPrice  transactionComplete\n",
              "0  123456779         Kulas Inc  99985  ...     5148       545                False\n",
              "1  123456784            GitHub  99986  ...     3262       383                False\n",
              "2  123456782         Kulas Inc  99990  ...     9119       407                 True\n",
              "3  123456783         My SQ Man  99999  ...     3097       615                False\n",
              "4  123456787         ABC Dogma  99996  ...     3356        91                 True\n",
              "5  123456778  Super Sexy Dingo  99996  ...     2474       136                 True\n",
              "6  123456783         ABC Dogma  99981  ...     4081       195                False\n",
              "7  123456785         ABC Dogma  99998  ...     6576       603                False\n",
              "8  123456778         Loolo INC  99997  ...     2460        36                False\n",
              "9  123456775         Kulas Inc  99997  ...     1831       664                 True\n",
              "\n",
              "[10 rows x 9 columns]"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 38
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "d_CNd0N3b_NE",
        "colab_type": "code",
        "outputId": "d0203359-9d3e-4c21-e1bf-816ce2c083cb",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 297
        }
      },
      "source": [
        "df.describe()"
      ],
      "execution_count": 39,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>Account</th>\n",
              "      <th>Order</th>\n",
              "      <th>Year</th>\n",
              "      <th>Quantity</th>\n",
              "      <th>UnitPrice</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>count</th>\n",
              "      <td>1.000000e+04</td>\n",
              "      <td>10000.000000</td>\n",
              "      <td>10000.000000</td>\n",
              "      <td>10000.000000</td>\n",
              "      <td>10000.000000</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>mean</th>\n",
              "      <td>1.234568e+08</td>\n",
              "      <td>99989.562900</td>\n",
              "      <td>1994.619800</td>\n",
              "      <td>4985.447300</td>\n",
              "      <td>355.866600</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>std</th>\n",
              "      <td>5.741156e+00</td>\n",
              "      <td>5.905551</td>\n",
              "      <td>14.432771</td>\n",
              "      <td>2868.949686</td>\n",
              "      <td>201.378478</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>min</th>\n",
              "      <td>1.234568e+08</td>\n",
              "      <td>99980.000000</td>\n",
              "      <td>1970.000000</td>\n",
              "      <td>0.000000</td>\n",
              "      <td>10.000000</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>25%</th>\n",
              "      <td>1.234568e+08</td>\n",
              "      <td>99985.000000</td>\n",
              "      <td>1982.000000</td>\n",
              "      <td>2505.750000</td>\n",
              "      <td>181.000000</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>50%</th>\n",
              "      <td>1.234568e+08</td>\n",
              "      <td>99990.000000</td>\n",
              "      <td>1995.000000</td>\n",
              "      <td>4994.000000</td>\n",
              "      <td>356.000000</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>75%</th>\n",
              "      <td>1.234568e+08</td>\n",
              "      <td>99995.000000</td>\n",
              "      <td>2007.000000</td>\n",
              "      <td>7451.500000</td>\n",
              "      <td>531.000000</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>max</th>\n",
              "      <td>1.234568e+08</td>\n",
              "      <td>99999.000000</td>\n",
              "      <td>2019.000000</td>\n",
              "      <td>9999.000000</td>\n",
              "      <td>700.000000</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ],
            "text/plain": [
              "            Account         Order          Year      Quantity     UnitPrice\n",
              "count  1.000000e+04  10000.000000  10000.000000  10000.000000  10000.000000\n",
              "mean   1.234568e+08  99989.562900   1994.619800   4985.447300    355.866600\n",
              "std    5.741156e+00      5.905551     14.432771   2868.949686    201.378478\n",
              "min    1.234568e+08  99980.000000   1970.000000      0.000000     10.000000\n",
              "25%    1.234568e+08  99985.000000   1982.000000   2505.750000    181.000000\n",
              "50%    1.234568e+08  99990.000000   1995.000000   4994.000000    356.000000\n",
              "75%    1.234568e+08  99995.000000   2007.000000   7451.500000    531.000000\n",
              "max    1.234568e+08  99999.000000   2019.000000   9999.000000    700.000000"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 39
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "jzwTIHn2cGVI",
        "colab_type": "code",
        "outputId": "1a194815-e0d1-42aa-82d2-654fc2ad6c0f",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 359
        }
      },
      "source": [
        "# Find values in order that exceeded \n",
        "df['TotalPrice'] = df['UnitPrice'] * df['Quantity']\n",
        "df.head(10)"
      ],
      "execution_count": 40,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>Account</th>\n",
              "      <th>Company</th>\n",
              "      <th>Order</th>\n",
              "      <th>SKU</th>\n",
              "      <th>Country</th>\n",
              "      <th>Year</th>\n",
              "      <th>Quantity</th>\n",
              "      <th>UnitPrice</th>\n",
              "      <th>transactionComplete</th>\n",
              "      <th>TotalPrice</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>123456779</td>\n",
              "      <td>Kulas Inc</td>\n",
              "      <td>99985</td>\n",
              "      <td>s9-supercomputer</td>\n",
              "      <td>Aruba</td>\n",
              "      <td>1981</td>\n",
              "      <td>5148</td>\n",
              "      <td>545</td>\n",
              "      <td>False</td>\n",
              "      <td>2805660</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>123456784</td>\n",
              "      <td>GitHub</td>\n",
              "      <td>99986</td>\n",
              "      <td>s4-supercomputer</td>\n",
              "      <td>Brazil</td>\n",
              "      <td>2001</td>\n",
              "      <td>3262</td>\n",
              "      <td>383</td>\n",
              "      <td>False</td>\n",
              "      <td>1249346</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>123456782</td>\n",
              "      <td>Kulas Inc</td>\n",
              "      <td>99990</td>\n",
              "      <td>s10-supercomputer</td>\n",
              "      <td>Montserrat</td>\n",
              "      <td>1973</td>\n",
              "      <td>9119</td>\n",
              "      <td>407</td>\n",
              "      <td>True</td>\n",
              "      <td>3711433</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3</th>\n",
              "      <td>123456783</td>\n",
              "      <td>My SQ Man</td>\n",
              "      <td>99999</td>\n",
              "      <td>s1-supercomputer</td>\n",
              "      <td>El Salvador</td>\n",
              "      <td>2015</td>\n",
              "      <td>3097</td>\n",
              "      <td>615</td>\n",
              "      <td>False</td>\n",
              "      <td>1904655</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>4</th>\n",
              "      <td>123456787</td>\n",
              "      <td>ABC Dogma</td>\n",
              "      <td>99996</td>\n",
              "      <td>s6-supercomputer</td>\n",
              "      <td>Poland</td>\n",
              "      <td>1970</td>\n",
              "      <td>3356</td>\n",
              "      <td>91</td>\n",
              "      <td>True</td>\n",
              "      <td>305396</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>5</th>\n",
              "      <td>123456778</td>\n",
              "      <td>Super Sexy Dingo</td>\n",
              "      <td>99996</td>\n",
              "      <td>s9-supercomputer</td>\n",
              "      <td>Costa Rica</td>\n",
              "      <td>2004</td>\n",
              "      <td>2474</td>\n",
              "      <td>136</td>\n",
              "      <td>True</td>\n",
              "      <td>336464</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>6</th>\n",
              "      <td>123456783</td>\n",
              "      <td>ABC Dogma</td>\n",
              "      <td>99981</td>\n",
              "      <td>s11-supercomputer</td>\n",
              "      <td>Spain</td>\n",
              "      <td>2006</td>\n",
              "      <td>4081</td>\n",
              "      <td>195</td>\n",
              "      <td>False</td>\n",
              "      <td>795795</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>7</th>\n",
              "      <td>123456785</td>\n",
              "      <td>ABC Dogma</td>\n",
              "      <td>99998</td>\n",
              "      <td>s9-supercomputer</td>\n",
              "      <td>Belarus</td>\n",
              "      <td>2015</td>\n",
              "      <td>6576</td>\n",
              "      <td>603</td>\n",
              "      <td>False</td>\n",
              "      <td>3965328</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>8</th>\n",
              "      <td>123456778</td>\n",
              "      <td>Loolo INC</td>\n",
              "      <td>99997</td>\n",
              "      <td>s8-supercomputer</td>\n",
              "      <td>Mauritius</td>\n",
              "      <td>1999</td>\n",
              "      <td>2460</td>\n",
              "      <td>36</td>\n",
              "      <td>False</td>\n",
              "      <td>88560</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>9</th>\n",
              "      <td>123456775</td>\n",
              "      <td>Kulas Inc</td>\n",
              "      <td>99997</td>\n",
              "      <td>s7-supercomputer</td>\n",
              "      <td>French Guiana</td>\n",
              "      <td>2004</td>\n",
              "      <td>1831</td>\n",
              "      <td>664</td>\n",
              "      <td>True</td>\n",
              "      <td>1215784</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ],
            "text/plain": [
              "     Account           Company  ...  transactionComplete TotalPrice\n",
              "0  123456779         Kulas Inc  ...                False    2805660\n",
              "1  123456784            GitHub  ...                False    1249346\n",
              "2  123456782         Kulas Inc  ...                 True    3711433\n",
              "3  123456783         My SQ Man  ...                False    1904655\n",
              "4  123456787         ABC Dogma  ...                 True     305396\n",
              "5  123456778  Super Sexy Dingo  ...                 True     336464\n",
              "6  123456783         ABC Dogma  ...                False     795795\n",
              "7  123456785         ABC Dogma  ...                False    3965328\n",
              "8  123456778         Loolo INC  ...                False      88560\n",
              "9  123456775         Kulas Inc  ...                 True    1215784\n",
              "\n",
              "[10 rows x 10 columns]"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 40
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "M1W2NgpKcdIV",
        "colab_type": "code",
        "outputId": "9692c64f-c5ba-4475-c2f1-6615a6f4719b",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 221
        }
      },
      "source": [
        "# Find transaction exceeded 3000000\n",
        "TotalTransaction = df[\"TotalPrice\"]\n",
        "TotalTransaction[np.abs(TotalTransaction) > 3000000]"
      ],
      "execution_count": 41,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "2       3711433\n",
              "7       3965328\n",
              "13      4758900\n",
              "15      5189372\n",
              "17      3989325\n",
              "         ...   \n",
              "9977    3475824\n",
              "9984    5251134\n",
              "9987    5670420\n",
              "9991    5735513\n",
              "9996    3018490\n",
              "Name: TotalPrice, Length: 2094, dtype: int64"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 41
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "DVCsCQoVewpn",
        "colab_type": "code",
        "outputId": "cf4e7483-9dbb-4f10-de45-57fe5a42c5b6",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 328
        }
      },
      "source": [
        "df[np.abs(TotalTransaction) > 6741112]"
      ],
      "execution_count": 42,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>Account</th>\n",
              "      <th>Company</th>\n",
              "      <th>Order</th>\n",
              "      <th>SKU</th>\n",
              "      <th>Country</th>\n",
              "      <th>Year</th>\n",
              "      <th>Quantity</th>\n",
              "      <th>UnitPrice</th>\n",
              "      <th>transactionComplete</th>\n",
              "      <th>TotalPrice</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>818</th>\n",
              "      <td>123456781</td>\n",
              "      <td>Gen Power</td>\n",
              "      <td>99991</td>\n",
              "      <td>s1-supercomputer</td>\n",
              "      <td>Burkina Faso</td>\n",
              "      <td>1985</td>\n",
              "      <td>9693</td>\n",
              "      <td>696</td>\n",
              "      <td>False</td>\n",
              "      <td>6746328</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1402</th>\n",
              "      <td>123456778</td>\n",
              "      <td>Will LLC</td>\n",
              "      <td>99985</td>\n",
              "      <td>s11-supercomputer</td>\n",
              "      <td>Austria</td>\n",
              "      <td>1990</td>\n",
              "      <td>9844</td>\n",
              "      <td>695</td>\n",
              "      <td>True</td>\n",
              "      <td>6841580</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2242</th>\n",
              "      <td>123456770</td>\n",
              "      <td>Name IT</td>\n",
              "      <td>99997</td>\n",
              "      <td>s9-supercomputer</td>\n",
              "      <td>Myanmar</td>\n",
              "      <td>1979</td>\n",
              "      <td>9804</td>\n",
              "      <td>692</td>\n",
              "      <td>False</td>\n",
              "      <td>6784368</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2876</th>\n",
              "      <td>123456772</td>\n",
              "      <td>Gen Power</td>\n",
              "      <td>99992</td>\n",
              "      <td>s10-supercomputer</td>\n",
              "      <td>Mali</td>\n",
              "      <td>2007</td>\n",
              "      <td>9935</td>\n",
              "      <td>679</td>\n",
              "      <td>False</td>\n",
              "      <td>6745865</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3210</th>\n",
              "      <td>123456782</td>\n",
              "      <td>Loolo INC</td>\n",
              "      <td>99991</td>\n",
              "      <td>s8-supercomputer</td>\n",
              "      <td>Kuwait</td>\n",
              "      <td>2006</td>\n",
              "      <td>9886</td>\n",
              "      <td>692</td>\n",
              "      <td>False</td>\n",
              "      <td>6841112</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3629</th>\n",
              "      <td>123456779</td>\n",
              "      <td>My SQ Man</td>\n",
              "      <td>99980</td>\n",
              "      <td>s3-supercomputer</td>\n",
              "      <td>Hong Kong</td>\n",
              "      <td>1994</td>\n",
              "      <td>9694</td>\n",
              "      <td>700</td>\n",
              "      <td>False</td>\n",
              "      <td>6785800</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>7674</th>\n",
              "      <td>123456781</td>\n",
              "      <td>Loolo INC</td>\n",
              "      <td>99989</td>\n",
              "      <td>s6-supercomputer</td>\n",
              "      <td>Sri Lanka</td>\n",
              "      <td>1994</td>\n",
              "      <td>9882</td>\n",
              "      <td>691</td>\n",
              "      <td>False</td>\n",
              "      <td>6828462</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>8645</th>\n",
              "      <td>123456789</td>\n",
              "      <td>Gen Power</td>\n",
              "      <td>99996</td>\n",
              "      <td>s11-supercomputer</td>\n",
              "      <td>Suriname</td>\n",
              "      <td>2005</td>\n",
              "      <td>9742</td>\n",
              "      <td>699</td>\n",
              "      <td>False</td>\n",
              "      <td>6809658</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>8684</th>\n",
              "      <td>123456785</td>\n",
              "      <td>Gen Power</td>\n",
              "      <td>99989</td>\n",
              "      <td>s2-supercomputer</td>\n",
              "      <td>Kenya</td>\n",
              "      <td>2013</td>\n",
              "      <td>9805</td>\n",
              "      <td>694</td>\n",
              "      <td>False</td>\n",
              "      <td>6804670</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ],
            "text/plain": [
              "        Account    Company  Order  ... UnitPrice transactionComplete  TotalPrice\n",
              "818   123456781  Gen Power  99991  ...       696               False     6746328\n",
              "1402  123456778   Will LLC  99985  ...       695                True     6841580\n",
              "2242  123456770    Name IT  99997  ...       692               False     6784368\n",
              "2876  123456772  Gen Power  99992  ...       679               False     6745865\n",
              "3210  123456782  Loolo INC  99991  ...       692               False     6841112\n",
              "3629  123456779  My SQ Man  99980  ...       700               False     6785800\n",
              "7674  123456781  Loolo INC  99989  ...       691               False     6828462\n",
              "8645  123456789  Gen Power  99996  ...       699               False     6809658\n",
              "8684  123456785  Gen Power  99989  ...       694               False     6804670\n",
              "\n",
              "[9 rows x 10 columns]"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 42
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "CrGqRDtiIc1v",
        "colab_type": "text"
      },
      "source": [
        "# Permunation and Random sampling"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "EcP-eneGIb-g",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 359
        },
        "outputId": "95e49583-7c30-417a-af84-80c536f894bc"
      },
      "source": [
        "dat = np.arange(80).reshape(10,8)\n",
        "df = pd.DataFrame(dat)\n",
        "\n",
        "df"
      ],
      "execution_count": 55,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>0</th>\n",
              "      <th>1</th>\n",
              "      <th>2</th>\n",
              "      <th>3</th>\n",
              "      <th>4</th>\n",
              "      <th>5</th>\n",
              "      <th>6</th>\n",
              "      <th>7</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>2</td>\n",
              "      <td>3</td>\n",
              "      <td>4</td>\n",
              "      <td>5</td>\n",
              "      <td>6</td>\n",
              "      <td>7</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>8</td>\n",
              "      <td>9</td>\n",
              "      <td>10</td>\n",
              "      <td>11</td>\n",
              "      <td>12</td>\n",
              "      <td>13</td>\n",
              "      <td>14</td>\n",
              "      <td>15</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>16</td>\n",
              "      <td>17</td>\n",
              "      <td>18</td>\n",
              "      <td>19</td>\n",
              "      <td>20</td>\n",
              "      <td>21</td>\n",
              "      <td>22</td>\n",
              "      <td>23</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3</th>\n",
              "      <td>24</td>\n",
              "      <td>25</td>\n",
              "      <td>26</td>\n",
              "      <td>27</td>\n",
              "      <td>28</td>\n",
              "      <td>29</td>\n",
              "      <td>30</td>\n",
              "      <td>31</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>4</th>\n",
              "      <td>32</td>\n",
              "      <td>33</td>\n",
              "      <td>34</td>\n",
              "      <td>35</td>\n",
              "      <td>36</td>\n",
              "      <td>37</td>\n",
              "      <td>38</td>\n",
              "      <td>39</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>5</th>\n",
              "      <td>40</td>\n",
              "      <td>41</td>\n",
              "      <td>42</td>\n",
              "      <td>43</td>\n",
              "      <td>44</td>\n",
              "      <td>45</td>\n",
              "      <td>46</td>\n",
              "      <td>47</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>6</th>\n",
              "      <td>48</td>\n",
              "      <td>49</td>\n",
              "      <td>50</td>\n",
              "      <td>51</td>\n",
              "      <td>52</td>\n",
              "      <td>53</td>\n",
              "      <td>54</td>\n",
              "      <td>55</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>7</th>\n",
              "      <td>56</td>\n",
              "      <td>57</td>\n",
              "      <td>58</td>\n",
              "      <td>59</td>\n",
              "      <td>60</td>\n",
              "      <td>61</td>\n",
              "      <td>62</td>\n",
              "      <td>63</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>8</th>\n",
              "      <td>64</td>\n",
              "      <td>65</td>\n",
              "      <td>66</td>\n",
              "      <td>67</td>\n",
              "      <td>68</td>\n",
              "      <td>69</td>\n",
              "      <td>70</td>\n",
              "      <td>71</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>9</th>\n",
              "      <td>72</td>\n",
              "      <td>73</td>\n",
              "      <td>74</td>\n",
              "      <td>75</td>\n",
              "      <td>76</td>\n",
              "      <td>77</td>\n",
              "      <td>78</td>\n",
              "      <td>79</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ],
            "text/plain": [
              "    0   1   2   3   4   5   6   7\n",
              "0   0   1   2   3   4   5   6   7\n",
              "1   8   9  10  11  12  13  14  15\n",
              "2  16  17  18  19  20  21  22  23\n",
              "3  24  25  26  27  28  29  30  31\n",
              "4  32  33  34  35  36  37  38  39\n",
              "5  40  41  42  43  44  45  46  47\n",
              "6  48  49  50  51  52  53  54  55\n",
              "7  56  57  58  59  60  61  62  63\n",
              "8  64  65  66  67  68  69  70  71\n",
              "9  72  73  74  75  76  77  78  79"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 55
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "KhcFpNm8JGqY",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 34
        },
        "outputId": "200e9d84-f898-470d-f2b5-fc862159ec8d"
      },
      "source": [
        "sampler = np.random.permutation(10)\n",
        "sampler"
      ],
      "execution_count": 60,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "array([1, 5, 3, 6, 2, 4, 9, 0, 7, 8])"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 60
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "oA1ZWkOxJH_6",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 359
        },
        "outputId": "9fada503-d996-4b5a-d1c7-c217341b3b0f"
      },
      "source": [
        "df.take(sampler)"
      ],
      "execution_count": 61,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>0</th>\n",
              "      <th>1</th>\n",
              "      <th>2</th>\n",
              "      <th>3</th>\n",
              "      <th>4</th>\n",
              "      <th>5</th>\n",
              "      <th>6</th>\n",
              "      <th>7</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>8</td>\n",
              "      <td>9</td>\n",
              "      <td>10</td>\n",
              "      <td>11</td>\n",
              "      <td>12</td>\n",
              "      <td>13</td>\n",
              "      <td>14</td>\n",
              "      <td>15</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>5</th>\n",
              "      <td>40</td>\n",
              "      <td>41</td>\n",
              "      <td>42</td>\n",
              "      <td>43</td>\n",
              "      <td>44</td>\n",
              "      <td>45</td>\n",
              "      <td>46</td>\n",
              "      <td>47</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3</th>\n",
              "      <td>24</td>\n",
              "      <td>25</td>\n",
              "      <td>26</td>\n",
              "      <td>27</td>\n",
              "      <td>28</td>\n",
              "      <td>29</td>\n",
              "      <td>30</td>\n",
              "      <td>31</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>6</th>\n",
              "      <td>48</td>\n",
              "      <td>49</td>\n",
              "      <td>50</td>\n",
              "      <td>51</td>\n",
              "      <td>52</td>\n",
              "      <td>53</td>\n",
              "      <td>54</td>\n",
              "      <td>55</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>16</td>\n",
              "      <td>17</td>\n",
              "      <td>18</td>\n",
              "      <td>19</td>\n",
              "      <td>20</td>\n",
              "      <td>21</td>\n",
              "      <td>22</td>\n",
              "      <td>23</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>4</th>\n",
              "      <td>32</td>\n",
              "      <td>33</td>\n",
              "      <td>34</td>\n",
              "      <td>35</td>\n",
              "      <td>36</td>\n",
              "      <td>37</td>\n",
              "      <td>38</td>\n",
              "      <td>39</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>9</th>\n",
              "      <td>72</td>\n",
              "      <td>73</td>\n",
              "      <td>74</td>\n",
              "      <td>75</td>\n",
              "      <td>76</td>\n",
              "      <td>77</td>\n",
              "      <td>78</td>\n",
              "      <td>79</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>2</td>\n",
              "      <td>3</td>\n",
              "      <td>4</td>\n",
              "      <td>5</td>\n",
              "      <td>6</td>\n",
              "      <td>7</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>7</th>\n",
              "      <td>56</td>\n",
              "      <td>57</td>\n",
              "      <td>58</td>\n",
              "      <td>59</td>\n",
              "      <td>60</td>\n",
              "      <td>61</td>\n",
              "      <td>62</td>\n",
              "      <td>63</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>8</th>\n",
              "      <td>64</td>\n",
              "      <td>65</td>\n",
              "      <td>66</td>\n",
              "      <td>67</td>\n",
              "      <td>68</td>\n",
              "      <td>69</td>\n",
              "      <td>70</td>\n",
              "      <td>71</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ],
            "text/plain": [
              "    0   1   2   3   4   5   6   7\n",
              "1   8   9  10  11  12  13  14  15\n",
              "5  40  41  42  43  44  45  46  47\n",
              "3  24  25  26  27  28  29  30  31\n",
              "6  48  49  50  51  52  53  54  55\n",
              "2  16  17  18  19  20  21  22  23\n",
              "4  32  33  34  35  36  37  38  39\n",
              "9  72  73  74  75  76  77  78  79\n",
              "0   0   1   2   3   4   5   6   7\n",
              "7  56  57  58  59  60  61  62  63\n",
              "8  64  65  66  67  68  69  70  71"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 61
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "99md1Z4GJQj9",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 142
        },
        "outputId": "b144e870-1821-4d23-aae4-78c03a1aeb19"
      },
      "source": [
        "# Random sample without replacement\n",
        "\n",
        "df.take(np.random.permutation(len(df))[:3])"
      ],
      "execution_count": 52,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>0</th>\n",
              "      <th>1</th>\n",
              "      <th>2</th>\n",
              "      <th>3</th>\n",
              "      <th>4</th>\n",
              "      <th>5</th>\n",
              "      <th>6</th>\n",
              "      <th>7</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>9</th>\n",
              "      <td>72</td>\n",
              "      <td>73</td>\n",
              "      <td>74</td>\n",
              "      <td>75</td>\n",
              "      <td>76</td>\n",
              "      <td>77</td>\n",
              "      <td>78</td>\n",
              "      <td>79</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>16</td>\n",
              "      <td>17</td>\n",
              "      <td>18</td>\n",
              "      <td>19</td>\n",
              "      <td>20</td>\n",
              "      <td>21</td>\n",
              "      <td>22</td>\n",
              "      <td>23</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>2</td>\n",
              "      <td>3</td>\n",
              "      <td>4</td>\n",
              "      <td>5</td>\n",
              "      <td>6</td>\n",
              "      <td>7</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ],
            "text/plain": [
              "    0   1   2   3   4   5   6   7\n",
              "9  72  73  74  75  76  77  78  79\n",
              "2  16  17  18  19  20  21  22  23\n",
              "0   0   1   2   3   4   5   6   7"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 52
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "TTMIv3DFJd68",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 34
        },
        "outputId": "8d56dadd-19d5-46e3-89ce-269e668fcc6b"
      },
      "source": [
        "# Random sample with replacement\n",
        "sack = np.array([4, 8, -2, 7, 5])\n",
        "sampler = np.random.randint(0, len(sack), size = 10)\n",
        "sampler"
      ],
      "execution_count": 53,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "array([3, 3, 0, 4, 0, 0, 1, 2, 1, 4])"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 53
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "sz1O1ITkJ0w2",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 34
        },
        "outputId": "18e6fb1e-d370-4c42-f822-11edcb5d85e8"
      },
      "source": [
        "draw = sack.take(sampler)\n",
        "draw"
      ],
      "execution_count": 54,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "array([ 7,  7,  4,  5,  4,  4,  8, -2,  8,  5])"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 54
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "GCJ5KRuvWW41",
        "colab_type": "text"
      },
      "source": [
        "# Dummy variables"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "aAPhGPlHWbAw",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 235
        },
        "outputId": "f763c6ff-5dad-49f1-b2cf-4ff986bbf16c"
      },
      "source": [
        "df = pd.DataFrame({'gender': ['female', 'female', 'male', 'unknown', 'male', 'female'], 'votes': range(6, 12, 1)})\n",
        "df"
      ],
      "execution_count": 69,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>gender</th>\n",
              "      <th>votes</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>female</td>\n",
              "      <td>6</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>female</td>\n",
              "      <td>7</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>male</td>\n",
              "      <td>8</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3</th>\n",
              "      <td>unknown</td>\n",
              "      <td>9</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>4</th>\n",
              "      <td>male</td>\n",
              "      <td>10</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>5</th>\n",
              "      <td>female</td>\n",
              "      <td>11</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ],
            "text/plain": [
              "    gender  votes\n",
              "0   female      6\n",
              "1   female      7\n",
              "2     male      8\n",
              "3  unknown      9\n",
              "4     male     10\n",
              "5   female     11"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 69
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "mBqTJ0EWYGzS",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 235
        },
        "outputId": "c0dd864c-ac1b-45a4-a116-00bf132f550e"
      },
      "source": [
        "pd.get_dummies(df['gender'])"
      ],
      "execution_count": 70,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>female</th>\n",
              "      <th>male</th>\n",
              "      <th>unknown</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3</th>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>4</th>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>5</th>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ],
            "text/plain": [
              "   female  male  unknown\n",
              "0       1     0        0\n",
              "1       1     0        0\n",
              "2       0     1        0\n",
              "3       0     0        1\n",
              "4       0     1        0\n",
              "5       1     0        0"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 70
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "6bTNv3jqYTR5",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 235
        },
        "outputId": "4acff651-22c0-4144-f8d1-d2b0dd79bd84"
      },
      "source": [
        "dummies = pd.get_dummies(df['gender'], prefix='gender')\n",
        "dummies"
      ],
      "execution_count": 71,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>gender_female</th>\n",
              "      <th>gender_male</th>\n",
              "      <th>gender_unknown</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3</th>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>4</th>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>5</th>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ],
            "text/plain": [
              "   gender_female  gender_male  gender_unknown\n",
              "0              1            0               0\n",
              "1              1            0               0\n",
              "2              0            1               0\n",
              "3              0            0               1\n",
              "4              0            1               0\n",
              "5              1            0               0"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 71
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "fTDLBPohYUaF",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 235
        },
        "outputId": "aba27eda-5499-4733-8efb-72702edf86ed"
      },
      "source": [
        "with_dummy = df[['votes']].join(dummies)\n",
        "with_dummy"
      ],
      "execution_count": 74,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>votes</th>\n",
              "      <th>gender_female</th>\n",
              "      <th>gender_male</th>\n",
              "      <th>gender_unknown</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>6</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>7</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>8</td>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3</th>\n",
              "      <td>9</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>4</th>\n",
              "      <td>10</td>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>5</th>\n",
              "      <td>11</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ],
            "text/plain": [
              "   votes  gender_female  gender_male  gender_unknown\n",
              "0      6              1            0               0\n",
              "1      7              1            0               0\n",
              "2      8              0            1               0\n",
              "3      9              0            0               1\n",
              "4     10              0            1               0\n",
              "5     11              1            0               0"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 74
        }
      ]
    }
  ]
}